c++ - Determining the Parameter Types of an Undefined Function -
i've learned cannot:
but i've learned can call decltype
return type of said function
so undefined function:
int foo(char, short);
i'd know if there's way can match parameter types types in tuple
. meta programming question. i'm shooting decltypeargs
in example:
enable_if_t<is_same_v<tuple<char, short>, decltypeargs<foo>>, int> bar;
can me understand how decltypeargs
crafted?
for non-overloaded functions, pointers functions, , pointers member functions, doing decltype(function)
gives type of function in unevaluated context, , type contains arguments.
so the argument types tuple, need lot of specializations:
// primary function objects template <class t> struct function_args : function_args<decltype(&t::operator()> { }; // normal function template <class r, class... args> struct function_args<r(args...)> { using type = std::tuple<args...>; }; // pointer non-cv-qualified, non-ref-qualified, non-variadic member function template <class r, class c, class... args> struct function_args<r (c::*)(args...)> : function_args<r(args...)> { }; // + few dozen more in c++14 // + few dozen more on top of noexcept being part of type system in c++17
with that:
template <class t> using decltypeargs = typename function_args<t>::type;
this requires write decltypeargs<decltype(foo)>
.
with c++17, have template <auto>
, above can be:
template <auto f> using decltypeargs = typename function_args<decltype(f)>::type;
and you'd decltypeargs<foo>
syntax.
Comments
Post a Comment