28 #ifndef __RTTR_FUNCTION_TRAITS_H__
29 #define __RTTR_FUNCTION_TRAITS_H__
33 #include <type_traits>
45 struct is_std_function : std::false_type
51 struct is_std_function<std::function<T>> : std::true_type
57 struct get_std_function_signature
63 struct get_std_function_signature<std::function<T>>
70 struct is_function_ptr : std::integral_constant<bool, std::is_pointer<T>::value &&
71 std::is_function<typename std::remove_pointer<T>::type>::value>
80 template<
typename... Args>
83 typedef std::tuple<Args...> arg_types;
89 struct function_traits_func_ptr;
91 template<
typename R,
typename... Args>
92 struct function_traits_func_ptr<R (*)(Args...)> : function_args<Args...>
94 static const size_t arg_count =
sizeof...(Args);
95 typedef R return_type;
101 struct function_traits_mem_ptr;
103 template<
typename R,
typename C,
typename... Args>
104 struct function_traits_mem_ptr<R (C::*)(Args...)> : function_args<Args...>
106 static const size_t arg_count =
sizeof...(Args);
107 typedef R return_type;
108 typedef C class_type;
111 template<
typename R,
typename C,
typename... Args>
112 struct function_traits_mem_ptr<R (C::*)(Args...) const> : function_args<Args...>
114 static const size_t arg_count =
sizeof...(Args);
115 typedef R return_type;
116 typedef C class_type;
119 template<
typename R,
typename C,
typename... Args>
120 struct function_traits_mem_ptr<R (C::*)(Args...) const volatile> : function_args<Args...>
122 static const size_t arg_count =
sizeof...(Args);
123 typedef R return_type;
124 typedef C class_type;
132 struct function_traits : std::conditional<std::is_member_function_pointer<T>::value,
133 function_traits_mem_ptr<T>,
134 typename std::conditional<std::is_function<T>::value,
135 function_traits_func_ptr<typename std::add_pointer<T>::type>,
136 typename std::conditional<is_std_function<T>::value,
137 function_traits_func_ptr<typename std::add_pointer<typename get_std_function_signature<T>::type>::type>,
138 function_traits_func_ptr<T>
147 template<
typename T,
size_t Index>
150 typedef typename std::tuple_element<Index, typename function_traits<T>::arg_types>::type type;
158 struct is_void_func : std::conditional<std::is_same<typename function_traits<T>::return_type, void>::value,
166 #endif // __RTTR_FUNCTION_TRAITS_H__