#ifndef SRC_UTIL_FUNCTION_TRAITS_H_ #define SRC_UTIL_FUNCTION_TRAITS_H_ #include using namespace std; namespace toolkit { template struct function_traits; //普通函数 template struct function_traits { public: enum { arity = sizeof...(Args) }; typedef Ret function_type(Args...); typedef Ret return_type; using stl_function_type = std::function; typedef Ret(*pointer)(Args...); template struct args { static_assert(I < arity, "index is out of range, index must less than sizeof Args"); using type = typename std::tuple_element >::type; }; }; //函数指针 template struct function_traits : function_traits{}; //std::function template struct function_traits> : function_traits{}; //member function #define FUNCTION_TRAITS(...) \ template \ struct function_traits : function_traits{}; \ FUNCTION_TRAITS() FUNCTION_TRAITS(const) FUNCTION_TRAITS(volatile) FUNCTION_TRAITS(const volatile) //函数对象 template struct function_traits : function_traits{}; } /* namespace toolkit */ #endif /* SRC_UTIL_FUNCTION_TRAITS_H_ */