// SPDX-FileCopyrightText: 2018 Kitsune Ral // SPDX-License-Identifier: LGPL-2.1-or-later #pragma once #include namespace Quotient { namespace _impl { template struct fn_traits {}; } /// Determine traits of an arbitrary function/lambda/functor /*! * Doesn't work with generic lambdas and function objects that have * operator() overloaded. * \sa * https://stackoverflow.com/questions/7943525/is-it-possible-to-figure-out-the-parameter-type-and-return-type-of-a-lambda#7943765 */ template struct function_traits : public _impl::fn_traits> {}; // Specialisation for a function template struct function_traits { using return_type = ReturnT; using arg_types = std::tuple; }; namespace _impl { template struct fn_object_traits; // Specialisation for a lambda function template struct fn_object_traits : function_traits {}; // Specialisation for a const lambda function template struct fn_object_traits : function_traits {}; // Specialisation for function objects with (non-overloaded) operator() // (this includes non-generic lambdas) template requires requires { &T::operator(); } struct fn_traits : public fn_object_traits {}; // Specialisation for a member function in a non-functor class template struct fn_traits : function_traits {}; // Specialisation for a const member function template struct fn_traits : function_traits {}; // Specialisation for a constref member function template struct fn_traits : function_traits {}; // Specialisation for a prvalue member function template struct fn_traits : function_traits {}; // Specialisation for a pointer-to-member template struct fn_traits : function_traits {}; // Specialisation for a const pointer-to-member template struct fn_traits : function_traits {}; } // namespace _impl template using fn_arg_t = std::tuple_element_t::arg_types>; template constexpr auto fn_arg_count_v = std::tuple_size_v::arg_types>; } // namespace Quotient n18'>18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133