I've been looking for a class in MPL that will create a function object from a sufficiently well-behaved MPL metafunction class. I hand-rolled this implementation:
template <class Lambda, class Result>
struct functor
{
typedef Result result_type;
template <typename Type>
Result operator()( Type )
{ return Lambda::template apply<Result>::type::value; }
};
A usage example would be
Foo foo;
return functor< boost::mpl::always<boost::mpl::int_<5> >, int >( foo );
as a glorified version of writing return 5
.
As this operation seems pretty basic, I'd have thought there is already a similar class in MPL, but a search of the documentation didn't yield anything for me. Am I missing something?