Boost Users :
Subject: [Boost-users] [Range] Range adaptors and compatibility with non-adapted iterators
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2012-01-11 00:23:37
Consider something like this:
themap_type::iterator search_for (int val)
return boost::find_if (themap|map_values, my_predicate(val));
The return from the function chokes because the adapted iterator type cannot be convered
back to the original type of iterator in the parent collection.
This is more general. If I wasn't just returning through but using the result within the
function, how do I test against end to see if find_if was successful?
auto it2= boost::find_if (themap|map_values, my_predicate(val));
if (it2 == themap::end()) // same problem!
This seems to be a problem with any algorithm that returns an iterator or otherwise makes
the iterators used within the algorithm visible outside of it, even if such usage is just
as an "end" flag and not really used to locate the element within the original collection
for subsequent iteration.
Am I missing something?
Is there a good reason why the filtered iterator can't give up the inner original iterator?
How do you use range adaptors in these situations?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net