[Bind][Lambda] Processing containers of pointers

Hi All I believe boost.bind has the capability to look through pointers and smart pointers to transparently process the pointed-to objects. Does boost.lambda.bind also have this capability? I.e., this bit of code (and I am specifically using boost 1.37 for this btw) #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> #include <boost/lambda/construct.hpp> #include <boost/shared_ptr.hpp> #include <algorithm> #include <vector> struct A { A( int ); void f( ); }; int main( ) { using namespace boost::lambda; std::vector< A * > pv; std::vector< boost::shared_ptr< A > > sv; std::for_each( pv.begin( ), pv.end( ), bind( &A::f, _1 ) ); std::for_each( sv.begin( ), sv.end( ), bind( &A::f, _1 ) ); // error here. } Thanks, - Rob.

2010/3/24 Robert Jones <robertgbjones@gmail.com>
Hi All
I believe boost.bind has the capability to look through pointers and smart pointers to transparently process the pointed-to objects. Does boost.lambda.bind also have this capability?
As your code demonstrates, lambda.bind works for pointers, but not for smart pointers. Roman Perepelitsa.

AMDG Peter Dimov wrote:
Robert Jones wrote:
I believe boost.bind has the capability to look through pointers and smart pointers to transparently process the pointed-to objects. Does boost.lambda.bind also have this capability?
No, but you should be able to use bind( &A::f, *_1 ) for that.
This should work unless A is an abstract type. In Christ, Steven Watanabe

On Wed, Mar 24, 2010 at 3:15 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
Peter Dimov wrote:
Robert Jones wrote:
I believe boost.bind has the capability to look through pointers and smart pointers to transparently process the pointed-to objects. Does boost.lambda.bind also have this capability?
No, but you should be able to use bind( &A::f, *_1 ) for that.
This should work unless A is an abstract type.
I don't understand this; if this passes by reference as Peter states in this thread, why can A not be an abstract type? - Rob.

AMDG Robert Jones wrote:
On Wed, Mar 24, 2010 at 3:15 PM, Steven Watanabe <watanabesj@gmail.com>wrote:
Peter Dimov wrote:
No, but you should be able to use bind( &A::f, *_1 ) for that.
This should work unless A is an abstract type.
I don't understand this; if this passes by reference as Peter states in this thread, why can A not be an abstract type?
Because of a long standing bug in the return type deduction mechanism. In Christ, Steven Watanabe

On Wed, Mar 24, 2010 at 11:39 AM, Peter Dimov <pdimov@pdimov.com> wrote:
Robert Jones wrote:
Hi All
I believe boost.bind has the capability to look through pointers and smart pointers to transparently process the pointed-to objects. Does boost.lambda.bind also have this capability?
No, but you should be able to use bind( &A::f, *_1 ) for that.
Which I imagine passes by value? Hence the original objects pointed to by the container pointers are unchanged? Is that the semantics implemented by boost::bind when it looks through smart pointers? Thanks, - Rob.

Robert Jones wrote:
On Wed, Mar 24, 2010 at 11:39 AM, Peter Dimov <pdimov@pdimov.com> wrote:
Robert Jones wrote:
Hi All
I believe boost.bind has the capability to look through pointers and smart pointers to transparently process the pointed-to objects. Does boost.lambda.bind also have this capability?
No, but you should be able to use bind( &A::f, *_1 ) for that.
Which I imagine passes by value?
It should pass by reference. You could also use bind( mem_fn( &A::f ), _1 ), if you like that better. This is what boost::bind does under the hood, more or less.
participants (4)
-
Peter Dimov
-
Robert Jones
-
Roman Perepelitsa
-
Steven Watanabe