In the question Is it possible to figure out the parameter type and return type of a lambda?
a nice implementation of a function_traits
struct is shown / linked.
This traits struct allows to determine
- return type
- function call type (i.e.
R(Ts ...)
) - function arity
- parameter type for each parameter
However it fails to work properly with default parameters. That is to say, only the complete type (including all default parameters) is considered to be the function's type.
Is it possible to write a
function_trait
which enables to check whether a given function parameter is a default parameter?
Specifically, I would like to use this trait later using SFINAE to enable / disable a given implementation based on the minimal / maximal arity of a function passed into the function, and the size of the parameter pack passed to the function.
template <typename Func, typename ... Ts>
std::enable_if<(function_trait<decltype(F)>::min_arity >= sizeof ... ( Ts )
and
function_trait<decltype(F)>::max_arity <= sizeof ... ( Ts ) )>::type
foo( Func F, Ts ... ts ){
F( ts ... );
}
Obviously this example is somewhat contrived.