28 Aug
2002
28 Aug
'02
2:17 p.m.
From: "Richard Wolf" <richard@student.usyd.edu.au>
Hi
I'm trying to use make_indirect_iterator on a container of shared_ptrs as follows:
[...]
int main() { list<shared_ptr<A> > List2;
// This doesn't work for_each(make_indirect_iterator(List2.begin()), make_indirect_iterator(List2.end()), mem_fun_ref(&A::f)); }
The reason is that make_indirect_iterator tries to instantiate std::iterator_traits< shared_ptr<A> >, and this fails, because shared_ptr<A> is not an iterator. You can make the for_each work by using for_each(List2.begin(), List2.end(), boost::mem_fn(&A::f)); // in <boost/mem_fn.hpp> if that's what you want.