Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-12-23 08:34:27


Thorsten Ottosen wrote:
> "Darren Cook" <darren_at_[hidden]> wrote in message
> news:3FE77A19.7050409_at_dcook.org...
>> I think the example needs to be more motivating :-).
>
> well, it's hard to put all the benefits into one small introducing
> example,
> but it could be beter than that.
>
>> Using normal vector:
>> for_each( svec.begin(), svec.end(), PolyPtrOps() );
>>
>> Using your class:
>> for_each( pvec.begin(), pvec.end(), mem_fun_ref( &Poly::foo )
>> );
>>
>> If saving writing a functor is all then we might as well use boost
>> lambda

Or mem_fn.

> not if we need to reuse the functor; you can't store a lambda
> expression and use it later.

If you want to demonstrate reuse you need a better example than

for_each( svec.begin(), svec.end(), mem_fn(&Poly::foo) );
for_each( pvec.begin(), pvec.end(), mem_fn(&Poly::foo) );

> PolyPtrOps() could be more complicated that shown.
>
>> or
>> bind:
>> for_each( svec.begin(), svec.end(), bind(&Poly::foo,_1) );
>
> does bind really works with smart pointers?

Yes it does. Try it.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk