我一直在寻找 MPL 中的一个类,它将从一个表现良好的 MPL 元函数类创建一个函数对象。我手动滚动了这个实现:
template <class Lambda, class Result>
struct functor
{
typedef Result result_type;
template <typename Type>
Result operator()( Type )
{ return Lambda::template apply<Result>::type::value; }
};
一个使用示例是
Foo foo;
return functor< boost::mpl::always<boost::mpl::int_<5> >, int >( foo );
作为写作的美化版本return 5
。
由于这个操作看起来很基本,我原以为 MPL 中已经有一个类似的类,但是搜索文档对我没有任何帮助。我错过了什么吗?