
----- Original Message ----- From: "Peter Dimov" <pdimov@mmltd.net> To: <Boost-Users@yahoogroups.com> Sent: Thursday, August 29, 2002 12:17 AM Subject: Re: [Boost-Users] shared_ptr and make_indirect_iterator
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.
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<boost::shared_ptr<foo> >) as if it were a container of the pointed-to type." Is the documentation incorrect, or have I misunderstood? Thanks Richard