ltj*_*jax 6 c++ lambda metaprogramming boost-mpl c++11
有没有办法将c ++ 0x lambda的签名,结果和参数类型推断为Boost.MPL序列,例如boost::mpl::vector?例如,对于lambda
[]( float a, int b ) -> void { std::cout << a << b << std::endl; }
Run Code Online (Sandbox Code Playgroud)
我想得到一个boost::mpl::vector<void,float,int>.
作为"闭包对象"的C++ 0x lambdas是仿函数.所以你可以使用boost.Boost.FunctionTypes来分解它operator().
例:
#include <boost/function_types/parameter_types.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/int.hpp>
int main()
{
int x = 1;
auto f = [x](char a, short b, int c){ return x; };
typedef decltype(f) lambda_t;
typedef boost::function_types::parameter_types<
decltype(&lambda_t::operator())>::type args_t;
// we can use boost::mpl::identity<decltype(f)>::type instead of lambda_t
static_assert(sizeof(boost::mpl::at<args_t, boost::mpl::int_<1>>::type) == 1, "");
}
Run Code Online (Sandbox Code Playgroud)