通过延迟函数调用

时间:2014-03-10 14:07:36

标签: c++11 bind functor

我有很多函子,我正在传递给函数来做一些测试工作。我的目标是使用std::bind执行这些操作而不使用lambdas。但是很简单的案例似乎很难用bind。我的第一个问题是here

现在我想知道是否存在可以使用bind创建的延迟函数调用。例如:auto foo = std::bind( std::placeholders::_1 )这样foo( 13 )将返回13。

1 个答案:

答案 0 :(得分:0)

这是linked question上给出的相同答案:

所以有一种方法可以使用std::integral_constant完成此任务:

const int thirteen = 13;
auto refWrap = bind( &std::integral_constant< int, thirteen >::operator int, std::integral_constant< int, thirteen >() );

这确实解决了这个问题,但是所有意图和目的都不如lambda:

const int thirteen = 13;
auto refWrap = [=](){ return thirteen; };
相关问题