-
July 22nd, 2014, 10:21 AM
#1
boost::bind
Can anyone explain (simply) what is meant by the symbols _1, _2, _3 etc, when used with boost::bind(). More importantly - was this supported by MSVC 8?
I'm trying to build some code that has statements like this one:-
Code:
clist.add_connection (_connect (boost::bind (&compositor, _1, _2, _3)));
It works well as long as I only use _1 and _2 - but anything higher than that and I'm seeing messages like:-
Code:
error C2039: '_3' is not a member of boost::lambda
So (for reasons I haven't figured out yet) _1 and _2 are getting interpreted as boost::lambda::_1 and boost::lambda::_2 - but my impression is that _1, _2, _3 etc are simply a parameter list to get passed to the bound function (i.e. they don't have anything to do with boost::lambda). Is this a feature that was only introduced more recently than MSVC 8?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
July 22nd, 2014, 10:44 AM
#2
Re: boost::bind
Originally Posted by John E
Can anyone explain (simply) what is meant by the symbols _1, _2, _3 etc, when used with boost::bind(). More importantly - was this supported by MSVC 8?
Read the Boost.Bind documentation. For example, it states:
It is possible to selectively bind only some of the arguments. bind(f, _1, 5)(x) is equivalent to f(x, 5); here _1 is a placeholder argument that means "substitute with the first input argument."
There are also notes about MSVC that suggest that this does work on MSVC8.
-
July 22nd, 2014, 11:35 AM
#3
Re: boost::bind
Thanks laserlight. I discovered that the addition of some global namespace qualifiers seems to be helping - i.e.
Code:
clist.add_connection (_connect (boost::bind (&compositor, ::_1, ::_2, ::_3)));
To be honest I'm not quite sure what I've done - but it does seem to get rid of the confusion with namespace boost::lambda (and it now compiles, even for '_3' and higher)..
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|