1 #ifndef SIPLASPLAS_UTILITY_FUNCTION_TRAITS_HPP 2 #define SIPLASPLAS_UTILITY_FUNCTION_TRAITS_HPP 6 #include <ctti/type_id.hpp> 11 enum class FunctionKind
16 CONST_MEMBER_FUNCTION,
30 static std::true_type check(decltype(&U::operator(),
nullptr));
32 static std::false_type check(...);
34 static constexpr
bool value = decltype(check<T>(
nullptr))::value;
37 template<
typename Function>
38 struct get_function_signature
40 static constexpr FunctionKind kind = FunctionKind::INVALID;
43 template<
typename R,
typename... Args>
44 struct get_function_signature<R(Args...)>
46 using args = meta::list<Args...>;
47 using return_type = R;
49 static constexpr FunctionKind kind = FunctionKind::FREE_FUNCTION;
52 template<
typename C,
typename R,
typename... Args>
53 struct get_function_signature<R (C::*)(Args...)> :
54 get_function_signature<R(Args...)>
56 static constexpr FunctionKind kind = FunctionKind::MEMBER_FUNCTION;
59 template<
typename C,
typename R,
typename... Args>
60 struct get_function_signature<R (C::*)(Args...) const> :
61 get_function_signature<R(Args...)>
63 static constexpr FunctionKind kind = FunctionKind::CONST_MEMBER_FUNCTION;
68 template<typename Function, bool IsFunctor = detail::IsFunctorClass<Function>::value>
69 struct function_signature :
public 70 detail::get_function_signature<Function>
73 template<
typename Functor>
74 struct function_signature<Functor, true> :
75 detail::get_function_signature<decltype(&Functor::operator())>
77 static constexpr FunctionKind kind = FunctionKind::FUNCTOR;
80 template<
typename Function>
81 using function_return_type =
typename function_signature<Function>::return_type;
83 template<
typename Function>
84 using function_arguments =
typename function_signature<Function>::args;
86 template<std::
size_t Index,
typename Function>
87 using function_argument = meta::get_t<Index, function_arguments<Function>>;
89 template<
typename Function>
90 constexpr FunctionKind function_kind()
92 return function_signature<Function>::kind;
95 template<
typename Function>
96 constexpr FunctionKind function_kind(Function)
98 return function_kind<Function>();
101 template<
typename A,
typename B>
102 struct equal_signature : std::is_same<
103 function_arguments<A>, function_arguments<B>
108 #endif // SIPLASPLAS_UTILITY_FUNCTION_TRAITS_HPP Definition: canary_allocator.hpp:7