Jump to content
  • Advertisement
Sign in to follow this  
chairthrower

boost bind and function

This topic is 3885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to do be able to do something whereby i partially bind a function or a method with some arguments - and then later when i have more information available i take that bound function and create a fully bound function with some additional arguments. example,
void myfunc( int a, int b) { /* do stuff */ }
boost::function< void ( int) > f1 = boost::bind( myfunc, 123, _1);	
boost::function< void () > f2 = f1( 456);  // <-- bind the last parameter with argument 

unfortunately the last line will call the function with the substituted arg rather than return a rebound function which i can then assign to f2. does anybody know if it possible to do something like this with boost?

Share this post


Link to post
Share on other sites
Advertisement
Have you tried:
void myfunc( int a, int b) { /* do stuff */ }
boost::function< void ( int) > f1 = boost::bind( myfunc, 123, _1);
boost::function< void () > f2 = boost::bind(f1, 456 _1);

Share this post


Link to post
Share on other sites
i didnt think of doing it like that - just have to drop the placeholder since its
now fully bound

boost::function< void ( int) > f1 = boost::bind( myfunc, 123, _1);
boost::function< void () > f2 = boost::bind(f1, 456 );
f2();


thanks heaps

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!