c++ - Get the type of a function parameter with boost::hana -
i know how type of function's parameter old way, wondering if there nice new way hana? example, want this:
struct foo { int func(float); }; auto getfunctype(auto t) -> declval<decltype(t)::type>()::func(type?) {} getfuntype(type_c<foo>); // should equal type_c<float> or similar
how type
here?
edit 6/21/2016 - minor changes match current version of library (0.4).
i'm author of callabletraits, library mentioned above @ildjarn (although not yet included in boost). arg_at_t
metafunction best way know parameter type member function, function, function pointer, function reference, or function object/lambda.
please keep in mind library undergoing significant changes, , linked documentation outdated (i.e. use @ own risk). if use it, recommend cloning develop branch. feature seeking, api not change.
for member function pointers, arg_at_t<0, mem_fn_ptr>
aliases equivalent of decltype(*this)
, account implicit this
pointer. so, case, this:
#include <type_traits> #include <callable_traits/arg_at.hpp> struct foo { int func(float); }; using func_param = callable_traits::arg_at_t<1, decltype(&foo::func)>; static_assert(std::is_same<func_param, float>::value, ""); int main(){}
then, can put boost::hana::type
or whatever use case requires.
Comments
Post a Comment