|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-08-14 07:58:10
"Peter Dimov" <pdimov_at_[hidden]> writes:
> goochrules! wrote:
>>> On Fri, 13 Aug 2004 01:52:05 -0700, Victor A. Wagner Jr.
>>> <vawjr_at_[hidden]> wrote:
>>>> std::list<boost::shared_ptr<tree> > forest;
>>>> of course you'll have to allocate (new) them before putting their
>>>> pointers in the list,
>>>> but that's not a huge issue.
>>> Not at all, so long as I use explicit temopries when calling new as
>>> the docs say.
>>> I've found I also have to change "iter->grow();" to
>>> "(*iter)->grow();", but I think i've found a mechanism to solve this.
>>> I create a wrapper around the iterator whose operator* and operator->
>>> returns a value_type& (i.e., *iter). The modified code is attached,
>>> any suggestions?
>
> You can also use mem_fn:
>
> for_each( forest.begin(), forest.end(), mem_fn(&tree::grow) );
>
> or bind, if grow takes arguments:
>
> for_each( forest.begin(), forest.end(), bind(&tree::grow, _1, 5) );
And, BTW, your iterator is not conforming and doesn't seem to be doing
what you want. See
http://www.boost.org/libs/iterator/doc/indirect_iterator.html for a
conforming solution.
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net