[odb-users] Avoid copying objects from odb::result

aongeeno at openmailbox.org aongeeno at openmailbox.org
Fri Jun 16 03:24:43 EDT 2017


> aongeeno at openmailbox.org <aongeeno at openmailbox.org> writes:
> 
> > How I can avoid copying objects in this code?
> > 
> > for (Category & c : r)
> >     //categories[c.id] = std::make_unique(c); ???
> 
> This is described in the manual, specifically, Section 4.4, "Query Result".
> 
> Boris
> 

Thank you! I solved my problem:

auto r(db_->query<Category>());
for ( auto it (r.begin()); it != r.end(); ++it)
{
	std::unique_ptr<Category> ptr(it.load());
    categories[it.id()] = std::move(ptr);
}




More information about the odb-users mailing list