template
struct function_traits
{
private:
using call_type = function_traits < decltype(&F::operator()) > ;
public:
using return_type = typename call_type::return_type;
static const std::size_t arity = call_type::arity - 1;
template
struct argument
{
static_assert(N < arity, "error: invalid parameter index.");
using type = typename call_type::template argument::type;
};
};
template
struct function_traits : public function_traits < R(Args...) >
{};
template
struct function_traits < R(Args...) >
{
using return_type = R;
static const std::size_t arity = sizeof...(Args);
template
struct argument
{
static_assert(N < arity, "error: invalid parameter index.");
using type = typename std::tuple_element>::type;
};
};
// member function pointer
template
struct function_traits : public function_traits < R(C&, Args...) >
{};
// const member function pointer
template
struct function_traits : public function_traits < R(C&, Args...) >
{};
// member object pointer
template
struct function_traits : public function_traits < R(C&) >
{};
template
struct function_traits : public function_traits < F >
{};
template
struct function_traits : public function_traits < F >
{};
auto f = [](int a, long b)
{
return a + b;
};
using Traits = function_traits;
static_assert(std::is_same::type, int>::value, "");