Boos.Bind: Binding to a placeholder address

Hi, Say have function I want to bind that expects an int*, but my placeholder _1 is of type int. How can I tell the bind function to bind "&_1"? I guess it would be something like: bind(myFun, address_of(_1)); Is this even possible? Thanks, Adi

Adi Shavit wrote:
Hi,
Say have function I want to bind that expects an int*, but my placeholder _1 is of type int. How can I tell the bind function to bind "&_1"?
I guess it would be something like: bind(myFun, address_of(_1));
Is this even possible?
You can switch to boost::lambda::bind and use &_1, or you can write address_of: template<class T> T * address_of( T & t ) { return &t; } and use boost::bind( myFun, boost::bind( &address_of<int>, _1 ) );

You can switch to boost::lambda::bind and use &_1, or you can write address_of:
template<class T> T * address_of( T & t ) { return &t; }
and use
boost::bind( myFun, boost::bind( &address_of<int>, _1 ) );
Thanks! I thought it should be that simple, I just assumed there would be such an adapter already inside boost. Thanks again, Adi

Adi Shavit wrote:
You can switch to boost::lambda::bind and use &_1, or you can write address_of:
template<class T> T * address_of( T & t ) { return &t; }
and use
boost::bind( myFun, boost::bind( &address_of<int>, _1 ) );
Thanks! I thought it should be that simple, I just assumed there would be such an adapter already inside boost.
Well, actually there is: http://www.boost.org/libs/utility/utility.htm#addressof ... and Peter is one of the authors ;-) Regards // Fredrik Blomqvist
participants (3)
-
Adi Shavit
-
Fredrik Blomqvist
-
Peter Dimov