How to use boost::lambda to create new object for an existing pointer?

168 Views Asked by At

What I want to do is --> create a new object in a new thread. Something like:

Class* object = 0;
Arg arg;
boost::thread t( lambda::bind( object = lambda::new_ptr< Class >()( boost::ref( arg ) );

it doesn't compile, what's correct way?

1

There are 1 best solutions below

1
JQ. On

Thanks to ildjarn, I tried with boost::phoenix and got it work, code is:

Class* object = 0;
CArg arg0;
Arg arg1;

boost::thread t( boost::phoenix::val( boost::ref( object ) ) = boost::phoenix::new_< Class >( boost::cref( arg0 ), boost::ref( arg1 ) );

Again, from ildjarn, the better code is:

Class* object = 0;

CArg arg0;

Arg arg1;

namespace phx = boost::phoenix;

boost::thread t( phx::ref( object ) = phx::new_< Class >( phx::cref( arg0 ), phx::ref( arg1 ) );