2
我可以使用boost :: bind或boost lambda函数库来创建忽略其参数并始终返回常量的仿函数吗?boost bind或返回常量的lambda仿函数
例如具有同等行为的函子:
int returnThree(SomeType arg) { return 3; }
我可以使用boost :: bind或boost lambda函数库来创建忽略其参数并始终返回常量的仿函数吗?boost bind或返回常量的lambda仿函数
例如具有同等行为的函子:
int returnThree(SomeType arg) { return 3; }
从上sehe的回答巴里的评论:
#include "boost/lambda/lambda.hpp"
...
auto returnThree = boost::lambda::constant(3);
当然,使用
boost::phoenix::val(3);
#include <boost/phoenix.hpp>
namespace p = boost::phoenix;
using namespace p::arg_names;
int main()
{
auto p = p::val(42);
return p() + p(/*ignored:*/77);
}
它返回84
作为退出码。
即使给你最多10个参数,而'提高::拉姆达:: constant'限你3。 – Barry 2014-10-28 15:13:39