CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: boost::bind

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: boost::bind

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    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
  •  





Click Here to Expand Forum to Full Width

Featured