
On 8/9/07, Joseph Gauterin <joseph.gauterin@googlemail.com> wrote:
Would anyone be interested in having a couple of extra specialized iterator adaptors in Boost.Iterator?
I'm thinking of 'key_iterator' and 'value_iterator' adaptors (along with convenience 'make_key_iterator' and 'make_value_iterator' functions) that allow any associative container (that follows standard library idioms) to be accessed as either a range of keys or as a range of values.
These would add very little that what transform_iterator already does. What would be more useful would be two function objects called first and second to access the first or the second element of a pair. Also function object wrappers for boost.tuple get<N> would really be useful. In addition to transform_iterator, they would be very useful in bind and boost.lambda expressions. BTW, I think that boost.bimap already provides them.
They'd be used like this:
std::map<std::string,int> m; std::for_each(make_value_iterator(m.begin()),make_value_iterator(m.end()),func);
With the above functors, you would spell that std::for_each( make_transform_iterator(m.begin(), second()), make_transform_iterator(m.end(), second())),func); At this point, is it really worth to have separate key/value_iterators? gpd