
An iterator is pointing to a pointer, how do I add another dereferencing
operator in the algorithm, so it works on values?
void f(int& i);
vector

Alexander Shyrokov
An iterator is pointing to a pointer, how do I add another dereferencing operator in the algorithm, so it works on values?
You might try http://www.boost.org/libs/iterator/indirect_iterator.html
void f(int& i); vector
a; // this would work if f would be void f(int* i) for_each(a.begin(),a.end(),boost::bind(f,_1)); I could define a dereferencing predicate: template<class T> struct deref{ typedef T result_type; T operator()(T* p){assert(p);return *p;} }; for_each(a.begin(),a.end(),boost::bind(f,boost::bind(deref<int>,_1)));
std::for_each( boost::make_indirect_iterator(a.begin()) , boost::make_indirect_iterator(a.end()) , some_operation ); -- Dave Abrahams Boost Consulting www.boost-consulting.com

Alexander Shyrokov wrote:
An iterator is pointing to a pointer, how do I add another dereferencing operator in the algorithm, so it works on values?
void f(int& i); vector
a; // this would work if f would be void f(int* i) for_each(a.begin(),a.end(),boost::bind(f,_1)); I could define a dereferencing predicate: template<class T> struct deref{ typedef T result_type; T operator()(T* p){assert(p);return *p;} }; for_each(a.begin(),a.end(),boost::bind(f,boost::bind(deref<int>,_1)));
but this requires supplying a template parameter. Is there an easier way?
Not with boost::bind, but Lambda allows you to write bind( f, *_1 ). You need to use Lambda's bind and _1 though. :-)
participants (3)
-
Alexander Shyrokov
-
David Abrahams
-
Peter Dimov