|
8 | 8 | #include <functional> |
9 | 9 | #include <numeric> |
10 | 10 | #include <tuple> |
| 11 | +#include <type_traits> |
11 | 12 | #include <utility> |
12 | 13 | #include <variant> |
13 | 14 |
|
@@ -286,6 +287,12 @@ struct nth_argument<Index, Ret(Args...) const> |
286 | 287 | template <std::size_t Index, function_type FunctionType> |
287 | 288 | using nth_argument_t = typename nth_argument<Index, FunctionType>::type; |
288 | 289 |
|
| 290 | +template <std::size_t Index, function_type FunctionType> |
| 291 | +constexpr decltype(auto) forward_arg( |
| 292 | + std::remove_reference_t<nth_argument_t<Index, FunctionType>>& t) noexcept { |
| 293 | + return static_cast<nth_argument_t<Index, FunctionType>&&>(t); |
| 294 | +} |
| 295 | + |
289 | 296 | template <bool Constness, typename Ret, typename... Args> |
290 | 297 | struct make_function_type : std::type_identity<Ret(Args...)> {}; |
291 | 298 |
|
@@ -988,75 +995,76 @@ constexpr auto operator""_method() noexcept { |
988 | 995 | } // namespace methods |
989 | 996 | } // namespace traits |
990 | 997 |
|
991 | | -#define traits_method_adder_lambda_(name, lambda_name, using_name, const_suffix) \ |
992 | | - constexpr auto lambda_name = []<function_type S, typename Type, typename InvokeMethod>() { \ |
993 | | - class with_arity_0 : public Type { \ |
994 | | - public: \ |
995 | | - using_name auto name() const_suffix { return std::invoke(InvokeMethod{}, this); } \ |
996 | | - \ |
997 | | - protected: \ |
998 | | - using Type::Type; \ |
999 | | - }; \ |
1000 | | - class with_arity_1 : public Type { \ |
1001 | | - public: \ |
1002 | | - using_name auto name(nth_argument_t<0, S> a0) const_suffix { \ |
1003 | | - return std::invoke(InvokeMethod{}, this, std::forward<decltype(a0)>(a0)); \ |
1004 | | - } \ |
1005 | | - \ |
1006 | | - protected: \ |
1007 | | - using Type::Type; \ |
1008 | | - }; \ |
1009 | | - class with_arity_2 : public Type { \ |
1010 | | - public: \ |
1011 | | - using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1) const_suffix { \ |
1012 | | - return std::invoke(InvokeMethod{}, this, std::forward<decltype(a0)>(a0), \ |
1013 | | - std::forward<decltype(a1)>(a1)); \ |
1014 | | - } \ |
1015 | | - \ |
1016 | | - protected: \ |
1017 | | - using Type::Type; \ |
1018 | | - }; \ |
1019 | | - class with_arity_3 : public Type { \ |
1020 | | - public: \ |
1021 | | - using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1, \ |
1022 | | - nth_argument_t<2, S> a2) const_suffix { \ |
1023 | | - return std::invoke(InvokeMethod{}, this, std::forward<decltype(a0)>(a0), \ |
1024 | | - std::forward<decltype(a1)>(a1), \ |
1025 | | - std::forward<decltype(a2)>(a2)); \ |
1026 | | - } \ |
1027 | | - \ |
1028 | | - protected: \ |
1029 | | - using Type::Type; \ |
1030 | | - }; \ |
1031 | | - class with_arity_4 : public Type { \ |
1032 | | - public: \ |
1033 | | - using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1, \ |
1034 | | - nth_argument_t<2, S> a2, nth_argument_t<3, S> a3) const_suffix { \ |
1035 | | - return std::invoke(InvokeMethod{}, this, std::forward<decltype(a0)>(a0), \ |
1036 | | - std::forward<decltype(a1)>(a1), std::forward<decltype(a2)>(a2), \ |
1037 | | - std::forward<decltype(a3)>(a3)); \ |
1038 | | - } \ |
1039 | | - \ |
1040 | | - protected: \ |
1041 | | - using Type::Type; \ |
1042 | | - }; \ |
1043 | | - class with_arity_5 : public Type { \ |
1044 | | - public: \ |
1045 | | - using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1, \ |
1046 | | - nth_argument_t<2, S> a2, nth_argument_t<3, S> a3, \ |
1047 | | - nth_argument_t<4, S> a4) const_suffix { \ |
1048 | | - return std::invoke(InvokeMethod{}, this, std::forward<decltype(a0)>(a0), \ |
1049 | | - std::forward<decltype(a1)>(a1), std::forward<decltype(a2)>(a2), \ |
1050 | | - std::forward<decltype(a3)>(a3), \ |
1051 | | - std::forward<decltype(a4)>(a4)); \ |
1052 | | - } \ |
1053 | | - \ |
1054 | | - protected: \ |
1055 | | - using Type::Type; \ |
1056 | | - }; \ |
1057 | | - return std::type_identity< \ |
1058 | | - ::traits::nth_t<::traits::arity<S>::value, with_arity_0, with_arity_1, with_arity_2, \ |
1059 | | - with_arity_3, with_arity_4, with_arity_5>>{}; \ |
| 998 | +#define traits_method_adder_lambda_(name, lambda_name, using_name, const_suffix) \ |
| 999 | + constexpr auto lambda_name = []<function_type S, typename Type, typename InvokeMethod>() { \ |
| 1000 | + class with_arity_0 : public Type { \ |
| 1001 | + public: \ |
| 1002 | + using_name auto name() const_suffix { return std::invoke(InvokeMethod{}, this); } \ |
| 1003 | + \ |
| 1004 | + protected: \ |
| 1005 | + using Type::Type; \ |
| 1006 | + }; \ |
| 1007 | + class with_arity_1 : public Type { \ |
| 1008 | + public: \ |
| 1009 | + using_name auto name(nth_argument_t<0, S> a0) const_suffix { \ |
| 1010 | + return std::invoke(InvokeMethod{}, this, ::traits::forward_arg<0, S>(a0)); \ |
| 1011 | + } \ |
| 1012 | + \ |
| 1013 | + protected: \ |
| 1014 | + using Type::Type; \ |
| 1015 | + }; \ |
| 1016 | + class with_arity_2 : public Type { \ |
| 1017 | + public: \ |
| 1018 | + using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1) const_suffix { \ |
| 1019 | + return std::invoke(InvokeMethod{}, this, ::traits::forward_arg<0, S>(a0), \ |
| 1020 | + ::traits::forward_arg<1, S>(a1)); \ |
| 1021 | + } \ |
| 1022 | + \ |
| 1023 | + protected: \ |
| 1024 | + using Type::Type; \ |
| 1025 | + }; \ |
| 1026 | + class with_arity_3 : public Type { \ |
| 1027 | + public: \ |
| 1028 | + using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1, \ |
| 1029 | + nth_argument_t<2, S> a2) const_suffix { \ |
| 1030 | + return std::invoke(InvokeMethod{}, this, ::traits::forward_arg<0, S>(a0), \ |
| 1031 | + ::traits::forward_arg<1, S>(a1), \ |
| 1032 | + ::traits::forward_arg<2, S>(a2)); \ |
| 1033 | + } \ |
| 1034 | + \ |
| 1035 | + protected: \ |
| 1036 | + using Type::Type; \ |
| 1037 | + }; \ |
| 1038 | + class with_arity_4 : public Type { \ |
| 1039 | + public: \ |
| 1040 | + using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1, \ |
| 1041 | + nth_argument_t<2, S> a2, nth_argument_t<3, S> a3) const_suffix { \ |
| 1042 | + return std::invoke(InvokeMethod{}, this, ::traits::forward_arg<0, S>(a0), \ |
| 1043 | + ::traits::forward_arg<1, S>(a1), \ |
| 1044 | + ::traits::forward_arg<2, S>(a2), \ |
| 1045 | + ::traits::forward_arg<3, S>(a3)); \ |
| 1046 | + } \ |
| 1047 | + \ |
| 1048 | + protected: \ |
| 1049 | + using Type::Type; \ |
| 1050 | + }; \ |
| 1051 | + class with_arity_5 : public Type { \ |
| 1052 | + public: \ |
| 1053 | + using_name auto name(nth_argument_t<0, S> a0, nth_argument_t<1, S> a1, \ |
| 1054 | + nth_argument_t<2, S> a2, nth_argument_t<3, S> a3, \ |
| 1055 | + nth_argument_t<4, S> a4) const_suffix { \ |
| 1056 | + return std::invoke( \ |
| 1057 | + InvokeMethod{}, this, ::traits::forward_arg<0, S>(a0), \ |
| 1058 | + ::traits::forward_arg<1, S>(a1), ::traits::forward_arg<2, S>(a2), \ |
| 1059 | + ::traits::forward_arg<3, S>(a3), ::traits::forward_arg<4, S>(a4)); \ |
| 1060 | + } \ |
| 1061 | + \ |
| 1062 | + protected: \ |
| 1063 | + using Type::Type; \ |
| 1064 | + }; \ |
| 1065 | + return std::type_identity< \ |
| 1066 | + ::traits::nth_t<::traits::arity<S>::value, with_arity_0, with_arity_1, with_arity_2, \ |
| 1067 | + with_arity_3, with_arity_4, with_arity_5>>{}; \ |
1060 | 1068 | } |
1061 | 1069 |
|
1062 | 1070 | #define traits_method_adder_(name) \ |
|
0 commit comments