C++0x 已弃用旧的绑定器,例如bind1st
并bind2nd
支持通用std::bind
. C++0x lambda 可以很好地绑定,std::bind
但它们不能与经典的 bind1st 和 bind2nd 绑定,因为默认情况下 lambda 没有嵌套的 typedef,例如argument_type
、first_argument_type
、second_argument_type
和result_type
. 所以我认为std::function
可以作为将 lambdas 绑定到旧绑定器的标准方法,因为它公开了必要的 typedef。
但是,std::function
在这种情况下很难使用 using,因为它会强制您在实例化函数类型时拼写出函数类型。
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.
我找不到方便的对象生成器std::function
。像这样的东西std::make_fuction
会很高兴。这样的事情存在吗?如果没有,还有其他更好的方法将 lamdas 绑定到经典活页夹吗?