Is there way to do something like this (MS VS 2008)?
boost::bind mybinder = boost::bind(/*something is binded here*/);
mybinder(/*parameters here*/); // <--- first call
mybinder(/*another parameters here*/); // <--- one more call
I tried
int foo(int){return 0;}
boost::bind<int(*)(int)> a = boost::bind(f, _1);
but it doesn’t work.
The bind returns unspecified type, so you can’t directly create a variable of the type. There is however a type template
boost::functionthat is constructible for any function or functor type. So:should do the trick. Plus if you are not binding any values, only placeholders, you can do without the
bindaltogether, becausefunctionis constructible from function pointers too. So:should work as long as
fisint f(int). The type made it to C++11 asstd::functionto be used with C++11 closures (andbind, which was also accepted):note, that for directly calling it in C++11, the new use of
autois easier:but if you want to pass it around,
std::functionstill comes in handy.