「クロージャオブジェクト」である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, "");
}
私はそれをどのように正確に行いますか?ファンクタ自体とその 'operator()'の両方にparameter_types、result_type、componentsを試しましたが、動作させることができませんでした。 – ltjax
サンプルのThanx。私はparameter_typesからpop'ingを終了し、フロントにresult_typeを追加しました - 魅力のように動作します! – ltjax