[odb-users] std::transform changes the begin iterator

Gamegou xiang.zhao at gamegou.com
Fri Dec 18 08:22:02 EST 2015


Hi Boris,

Thank you, I got it. I didn't notice that sections.

I'll copy the result to vector before proceed.

Regards
Zhao Xiang

> 在 2015年10月27日,20:50,Boris Kolpackov <boris at codesynthesis.com> 写道:
> 
> Hi,
> 
> Zhao Xiang <xiang.zhao at gamegou.com> writes:
> 
>> odb::result<user_player> players = db.query<user_player>(...);
>> 
>> std::vector<uint32_t> playerIds;
>> playerIds.resize(players.size());
>> std::transform(players.begin(), players.end(), playerIds.begin(), ...);
>> 
>> assert(players.size() > 0);//ok
>> assert(players.begin() != players.end());//oops
>> 
>> After some debug I noticed the value of players.begin() is changed
>> after the std::transform call.
> 
> From Section 4.4, "Query Result":
> 
> "It is best to view an instance of odb::result as a handle to a stream, such
> as a socket stream. While we can make a copy of a result or assign one result
> to another, the two instances will refer to the same result stream. Advancing
> the current position in one instance will also advance it in another."
> 
> And:
> 
> "The result iterator is an input iterator which means that the only two
> position operations that it supports are to move to the next object and to
> determine whether the end of the result stream has been reached. In fact, the
> result iterator can only be in two states: the current position and the end
> position. If we have two iterators pointing to the current position and then
> we advance one of them, the other will advance as well."
> 
> Which means that after you have iterated over the result, (in transform()),
> you cannot re-iterate over it without re-executing the query.
> 
> Boris




More information about the odb-users mailing list