Using deprecated binders and C++0x lambdas
- by Sumant
C++0x has deprecated the use of old binders such as bind1st and bind2nd in favor of generic std::bind. C++0x lambdas bind nicely with std::bind but they don't bind with classic bind1st and bind2nd because by default lambdas don't have nested typedefs such as argument_type, first_argument_type, second_argument_type, and result_type.
So I thought std::function can serve as a standard way to bind lambdas to the old binders because it exposes the necessary typedefs.
However, using std::function is hard to use in this context because it forces you to spell out the function-type while instantiating it.
auto bound =
std::bind1st(std::function<int (int, int)>([](int i, int j){ return i < j; }), 10); // hard to use
auto bound =
std::bind1st(std::make_function([](int i, int j){ return i < j; }), 10); // nice to have but does not compile.
I could not find a convenient object generator for std::function. Something like std::make_fuction would be nice to have. Does such a thing exist? If not, is there any other better way of binding lamdas to the classic binders?