CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    What exaxctly does boost::bind do ??

    What does boost:bind do? I've never really thought about it before (I simply took it for granted) but apparently, this statement is perfectly valid code...
    Code:
    boost::bind(some_function_name);
    but what exactly does it do
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    Oct 2008
    Posts
    1,456

    Re: What exaxctly does boost::bind do ??

    as far as I know, the main reason is to allow composition with nullary functions:

    Code:
    int foo();
    void bar( int c );
    
    int main() {
      bar( foo() ); // this is the expression we want to bind
      bind( bar, foo )(); // this won't compile, as if calling bar(foo);
      bind( bar, foo() )(); // this works, but it's not what we really want ( foo is invoked once at bind time )
      bind( bar, bind(foo) )(); // this works: bind turns foo into a nullary bind expression, informing the outer bind that a composition is requested
    }
    Last edited by superbonzo; August 23rd, 2017 at 07:39 AM. Reason: improved answer

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