1 #ifndef SIPLASPLAS_UTILITY_FUNCTION_TRAITS_HPP 2 #define SIPLASPLAS_UTILITY_FUNCTION_TRAITS_HPP 6 #include <ctti/type_id.hpp> 11 enum class FunctionKind
17 CONST_MEMBER_FUNCTION,
31 static std::true_type check(decltype(&U::operator(),
nullptr));
33 static std::false_type check(...);
35 static constexpr
bool value = decltype(check<T>(
nullptr))::value;
38 template<
typename Function>
39 struct get_function_signature
41 using args = meta::list<>;
42 static constexpr FunctionKind kind = FunctionKind::INVALID;
45 template<
typename R,
typename... Args>
46 struct get_function_signature<R(Args...)>
48 using args = meta::list<Args...>;
49 using args_without_this = args;
50 using return_type = R;
52 static constexpr FunctionKind kind = FunctionKind::FREE_FUNCTION;
55 template<
typename R,
typename... Args>
56 struct get_function_signature<R(*)(Args...)> :
57 public get_function_signature<R(Args...)>
60 template<
typename C,
typename R,
typename... Args>
61 struct get_function_signature<R (C::*)(Args...)>
63 using args = meta::list<C, Args...>;
64 using args_without_this = meta::list<Args...>;
65 using return_type = R;
66 static constexpr FunctionKind kind = FunctionKind::MEMBER_FUNCTION;
69 template<
typename C,
typename R,
typename... Args>
70 struct get_function_signature<R (C::*)(Args...) const>
72 using args = meta::list<C, Args...>;
73 using args_without_this = meta::list<Args...>;
74 using return_type = R;
75 static constexpr FunctionKind kind = FunctionKind::CONST_MEMBER_FUNCTION;
82 template<
typename T,
typename Class>
83 struct get_function_signature<T Class::*>
85 using args = meta::list<Class>;
86 using args_without_this = meta::list<>;
87 using return_type = T;
88 static constexpr FunctionKind kind = FunctionKind::MEMBER_OBJECT;
92 template<typename Function, bool IsFunctor = detail::IsFunctorClass<Function>::value>
93 struct function_signature :
public 94 detail::get_function_signature<Function>
97 template<
typename Functor>
98 struct function_signature<Functor, true>
103 using args = meta::tail_t<
104 typename detail::get_function_signature<decltype(&Functor::operator())>::args
106 using args_without_this = args;
107 using return_type =
typename detail::get_function_signature<decltype(&Functor::operator())>::return_type;
109 static constexpr FunctionKind kind = FunctionKind::FUNCTOR;
112 template<
typename Function>
113 using function_return_type =
typename function_signature<Function>::return_type;
115 template<
typename Function>
116 using function_arguments =
typename function_signature<Function>::args;
118 template<
typename Function>
119 using function_arguments_without_this =
typename function_signature<Function>::args_without_this;
121 template<std::
size_t Index,
typename Function>
122 using function_argument = meta::get_t<Index, function_arguments<Function>>;
124 template<
typename Function>
125 constexpr FunctionKind function_kind()
127 return function_signature<Function>::kind;
130 template<
typename Function>
131 constexpr FunctionKind function_kind(Function)
133 return function_kind<Function>();
136 template<
typename A,
typename B>
137 struct equal_signature : std::is_same<
138 function_arguments_without_this<A>, function_arguments_without_this<B>
143 #endif // SIPLASPLAS_UTILITY_FUNCTION_TRAITS_HPP Definition: canary_allocator.hpp:7