#pragma once #include // Modified from https://stackoverflow.com/questions/7943525/is-it-possible-to-figure-out-the-parameter-type-and-return-type-of-a-lambda // Fallback, anything with an operator() template struct function_traits : public function_traits { }; // Pointers to class members that are themselves functors. // For example, in the following code: // template // struct S { // func_t f; // }; // template // S make_s(func_t f) { // return S { .f = f }; // } // // auto s = make_s([] (int, float) -> double { /* ... */ }); // // function_traits traits; template struct function_traits : public function_traits { }; // Const class member functions template struct function_traits : public function_traits { }; // Reference types template struct function_traits : public function_traits {}; template struct function_traits : public function_traits {}; // Free functions template struct function_traits { // arity is the number of arguments. enum { arity = sizeof...(Args) }; typedef std::tuple ArgsTuple; typedef ReturnType result_type; template struct arg { typedef typename std::tuple_element>::type type; // the i-th argument is equivalent to the i-th tuple element of a tuple // composed of those arguments. }; }; template struct nullary_function_traits { using traits = function_traits; using result_type = typename traits::result_type; }; template struct unary_function_traits { using traits = function_traits; using result_type = typename traits::result_type; using arg1_t = typename traits::template arg<0>::type; }; template struct binary_function_traits { using traits = function_traits; using result_type = typename traits::result_type; using arg1_t = typename traits::template arg<0>::type; using arg2_t = typename traits::template arg<1>::type; }; // Traits for calling with c10::guts::invoke, where member_functions have a first argument of ClassType template struct invoke_traits : public function_traits{ }; template struct invoke_traits : public invoke_traits{ }; template struct invoke_traits : public invoke_traits{ }; template struct invoke_traits : public function_traits { }; template struct invoke_traits : public function_traits { };