Björn Karlsson
...and now that we've seen the fundamental mechanics involved in using
transform_iterator for this
problem, here's a really terse version using two other useful libraries; Boost.Bind and Boost.Function.
typedef boost::transform_iterator< boost::function
, container_type::iterator> iterator_type; The advantages of this approach are that it's short, elegant, and all the logic is locally defined.
Hello, I see a possible disadvantage: efficiency. I may be wrong but I see there will be the extra overhead of a call through boost::function for every iterator dereference. That is, compared to the version using the functor which would have no overhead (compared to a hand-made iterator that dereferenced the second element of a pair). Please correct me if I'm wrong with this. Thanks! PS: when i try to propose using boost I always get: 'Hum... what's the overhead compared to doing it by hand?'