The Boost transform_iterator option is used here:
#include <list> #include <boost/iterator/transform_iterator.hpp> #include <tr1/memory> #include <tr1/functional> using std::list; using std::tr1::shared_ptr; using boost::transform_iterator; using boost::make_transform_iterator; using std::tr1::mem_fn; using std::tr1::function; struct Foo {}; struct Bar { typedef shared_ptr< Foo > Ptr; typedef list< Ptr > List; typedef function< Foo* (Ptr) > Functor; typedef transform_iterator< Functor, List::iterator > Iterator; Iterator begin() { return make_transform_iterator( fooptrs.begin(), mem_fn( &Ptr::get ) ); } Iterator end() { return make_transform_iterator( fooptrs.end(), mem_fn( &Ptr::get ) ); } List fooptrs; };
C ++ 11 will simplify the removal of the function
shell, but I don't have a compiler that could test it. You can also hide a specific Iterator
type using erase erase if you see the need (I think Adobe offers a free any_iterator
class any_iterator
for this purpose.)
source share