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 static constexpr FunctionKind kind = FunctionKind::INVALID;
44 template<
typename R,
typename... Args>
45 struct get_function_signature<R(Args...)>
47 using args = meta::list<Args...>;
48 using args_without_this = args;
49 using return_type = R;
51 static constexpr FunctionKind kind = FunctionKind::FREE_FUNCTION;
54 template<
typename R,
typename... Args>
55 struct get_function_signature<R(*)(Args...)> :
56 public get_function_signature<R(Args...)>
59 template<
typename C,
typename R,
typename... Args>
60 struct get_function_signature<R (C::*)(Args...)>
62 using args = meta::list<C, Args...>;
63 using args_without_this = meta::list<Args...>;
64 using return_type = R;
65 static constexpr FunctionKind kind = FunctionKind::MEMBER_FUNCTION;
68 template<
typename C,
typename R,
typename... Args>
69 struct get_function_signature<R (C::*)(Args...) const>
71 using args = meta::list<C, Args...>;
72 using args_without_this = meta::list<Args...>;
73 using return_type = R;
74 static constexpr FunctionKind kind = FunctionKind::CONST_MEMBER_FUNCTION;
81 template<
typename T,
typename Class>
82 struct get_function_signature<T Class::*>
84 using args = meta::list<Class>;
85 using args_without_this = meta::list<>;
86 using return_type = T;
87 static constexpr FunctionKind kind = FunctionKind::MEMBER_OBJECT;
91 template<typename Function, bool IsFunctor = detail::IsFunctorClass<Function>::value>
92 struct function_signature :
public 93 detail::get_function_signature<Function>
96 template<
typename Functor>
97 struct function_signature<Functor, true>
102 using args = meta::tail_t<
103 typename detail::get_function_signature<decltype(&Functor::operator())>::args
105 using args_without_this = args;
106 using return_type =
typename detail::get_function_signature<decltype(&Functor::operator())>::return_type;
108 static constexpr FunctionKind kind = FunctionKind::FUNCTOR;
111 template<
typename Function>
112 using function_return_type =
typename function_signature<Function>::return_type;
114 template<
typename Function>
115 using function_arguments =
typename function_signature<Function>::args;
117 template<
typename Function>
118 using function_arguments_without_this =
typename function_signature<Function>::args_without_this;
120 template<std::
size_t Index,
typename Function>
121 using function_argument = meta::get_t<Index, function_arguments<Function>>;
123 template<
typename Function>
124 constexpr FunctionKind function_kind()
126 return function_signature<Function>::kind;
129 template<
typename Function>
130 constexpr FunctionKind function_kind(Function)
132 return function_kind<Function>();
135 template<
typename A,
typename B>
136 struct equal_signature : std::is_same<
137 function_arguments_without_this<A>, function_arguments_without_this<B>
142 #endif // SIPLASPLAS_UTILITY_FUNCTION_TRAITS_HPP Definition: canary_allocator.hpp:7