Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-08-13 17:29:48

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) );

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at