Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include "Utilities/TMPL.hpp" 7 : 8 : namespace tt { 9 : /// \cond 10 : namespace detail { 11 : template <typename T> 12 : struct function_info_impl; 13 : 14 : template <typename Ret, typename... Args> 15 : struct function_info_impl<Ret(Args...)> { 16 : using return_type = Ret; 17 : using argument_types = tmpl::list<Args...>; 18 : using class_type = void; 19 : }; 20 : 21 : template <typename Ret, typename... Args> 22 : struct function_info_impl<Ret(Args...) noexcept> { 23 : using return_type = Ret; 24 : using argument_types = tmpl::list<Args...>; 25 : using class_type = void; 26 : }; 27 : 28 : #define FUNCTION_INFO_IMPL_FUNCTION_PTR(MODIFIERS, NOEXCEPT_STATUS) \ 29 : template <typename Ret, \ 30 : typename... Args> /* NOLINTNEXTLINE(misc-macro-parentheses) */ \ 31 : struct function_info_impl<Ret (*MODIFIERS)(Args...) NOEXCEPT_STATUS> { \ 32 : using return_type = Ret; \ 33 : using argument_types = tmpl::list<Args...>; \ 34 : using class_type = void; \ 35 : } 36 : 37 : FUNCTION_INFO_IMPL_FUNCTION_PTR(, ); 38 : FUNCTION_INFO_IMPL_FUNCTION_PTR(, noexcept); 39 : FUNCTION_INFO_IMPL_FUNCTION_PTR(const, ); 40 : FUNCTION_INFO_IMPL_FUNCTION_PTR(const, noexcept); 41 : FUNCTION_INFO_IMPL_FUNCTION_PTR(volatile, ); 42 : FUNCTION_INFO_IMPL_FUNCTION_PTR(volatile, noexcept); 43 : FUNCTION_INFO_IMPL_FUNCTION_PTR(const volatile, ); 44 : FUNCTION_INFO_IMPL_FUNCTION_PTR(const volatile, noexcept); 45 : #undef FUNCTION_INFO_IMPL_FUNCTION_PTR 46 : 47 : #define FUNCTION_INFO_IMPL_CLASS(MODIFIERS) \ 48 : template <typename Ret, typename Class, \ 49 : typename... Args> /* NOLINTNEXTLINE(misc-macro-parentheses) */ \ 50 : struct function_info_impl<Ret (Class::*)(Args...) MODIFIERS> { \ 51 : using return_type = Ret; \ 52 : using argument_types = tmpl::list<Args...>; \ 53 : using class_type = Class; \ 54 : } 55 : 56 : FUNCTION_INFO_IMPL_CLASS(); 57 : FUNCTION_INFO_IMPL_CLASS(const); 58 : FUNCTION_INFO_IMPL_CLASS(noexcept); 59 : FUNCTION_INFO_IMPL_CLASS(volatile); 60 : FUNCTION_INFO_IMPL_CLASS(const noexcept); 61 : FUNCTION_INFO_IMPL_CLASS(const volatile); 62 : FUNCTION_INFO_IMPL_CLASS(const volatile noexcept); 63 : FUNCTION_INFO_IMPL_CLASS(volatile noexcept); 64 : #undef FUNCTION_INFO_IMPL_CLASS 65 : } // namespace detail 66 : /// \endcond 67 : 68 : /*! 69 : * \ingroup TypeTraitsGroup 70 : * \brief Returns a struct that contains the return type, argument types, and 71 : * the class type if the `F` is a non-static member function 72 : * 73 : * The return class has member type aliases: 74 : * - `return_type` The return type of the function 75 : * - `argument_types` A `tmpl::list` of the arguments types of the function 76 : * - `class_type` The type of the class if the function is a non-static member 77 : * function, otherwise `void` 78 : * 79 : * \note For static member variables the class will be `void` because they are 80 : * effectively free functions. 81 : */ 82 : template <typename F> 83 1 : using function_info = detail::function_info_impl<F>; 84 : } // namespace tt