有没有办法推断λ的签名作为mpl序列? [英] Is there a way to deduce the signature of a lambda as an mpl sequence?
本文介绍了有没有办法推断λ的签名作为mpl序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法来推导c ++ 0x lambda的签名,结果和参数类型作为Boost.MPL序列,例如 boost :: mpl :: vector
?例如,对于lambda
[](float a,int b) - > void {std :: cout< a<< b<< std :: endl; }
我想获得一个 boost :: mpl :: vector<
C ++ 0x lambdas,它们是闭包对象 是函子。因此,您可以使用boost.Boost.FunctionTypes来分解其运算符()
。
示例:
#include< boost / function_types / parameter_types.hpp>
#include< boost / mpl / at.hpp>
#include< boost / mpl / int.hpp>
int main()
{
int x = 1;
self 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;
//我们可以使用boost :: mpl :: identity< decltype(f)> :: type代替lambda_t
static_assert(sizeof(boost :: mpl :: at& ,boost :: mpl :: int_>> :: type)== 1,);
}
Is there a way to deduce the signature, result- and parameter-types, of a c++0x lambda as a Boost.MPL sequence, for example a boost::mpl::vector
? For example, for a lambda
[]( float a, int b ) -> void { std::cout << a << b << std::endl; }
I would like to get a boost::mpl::vector<void,float,int>
.
解决方案
C++0x lambdas which are "closure-objects" are functors. So you can use boost.Boost.FunctionTypes to decompose its operator()
.
Example:
#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, "");
}
这篇关于有没有办法推断λ的签名作为mpl序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文