Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-11-21 20:11:23


Mark Santaniello (AMD) wrote:

> template< typename T >
> boost::function<T(T)> foo( T n_ )
> {
> //Works, but leaks n
> //T *n = new T( n_ );
>
> //Doesn't work
> boost::shared_ptr<T> n( new T(n_) );
>
> return ( *n += _1 );

I think that you need to wrap n in boost::lambda::constant:

    return *constant(n) += _1;

Without it, *n is evaluated immediately.

> }


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