----- Original Message -----
From: "Peter Dimov"
From: "Richard Wolf"
Hi
I'm trying to use make_indirect_iterator on a container of shared_ptrs as follows:
[...]
int main() { list
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
if that's what you want.
Thank you. I suppose this means that the container must contain a type that
is an iterator rather than a pointer. A raw pointer works because raw
pointers are iterators. But....
The documentation of Indirect Iterator Adapter says :
"The indirect iterator adaptor augments an iterator by applying an extra
dereference inside of operator*(). For example, this iterator makes it
possible to view a container of pointers or smart-pointers (e.g.
std::list