Skip to content

Commit 348ecd1

Browse files
committed
Replace nth_argument_of with argument_of
gcc-10.x, clang-12.x, is not handling variable arguments correctly. As we need only one argument the helper was reduced to only one arg.
1 parent 367e9d4 commit 348ecd1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

include/cpp2util.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,20 +1175,20 @@ constexpr auto is( std::monostate const& ) -> std::true_type {
11751175
return {};
11761176
}
11771177

1178-
template<std::size_t I, typename Ret, typename... Args>
1179-
auto nth_argument_of_helper(Ret(*) (Args...)) -> std::tuple_element_t<I, std::tuple<Args...>>;
1178+
template<typename Ret, typename Arg>
1179+
auto argument_of_helper(Ret(*) (Arg)) -> Arg;
11801180

1181-
template<std::size_t I, typename Ret, typename F, typename... Args>
1182-
auto nth_argument_of_helper(Ret(F::*) (Args...)) -> std::tuple_element_t<I, std::tuple<Args...>>;
1181+
template<typename Ret, typename F, typename Arg>
1182+
auto argument_of_helper(Ret(F::*) (Arg)) -> Arg;
11831183

1184-
template<std::size_t I, typename Ret, typename F, typename... Args>
1185-
auto nth_argument_of_helper(Ret(F::*) (Args...) const) -> std::tuple_element_t<I, std::tuple<Args...>>;
1184+
template<typename Ret, typename F, typename Arg>
1185+
auto argument_of_helper(Ret(F::*) (Arg) const) -> Arg;
11861186

1187-
template <std::size_t I, typename F>
1188-
auto nth_argument_of_helper(F) -> CPP2_TYPEOF(nth_argument_of_helper<I>(&F::operator()));
1187+
template <typename F>
1188+
auto argument_of_helper(F) -> CPP2_TYPEOF(argument_of_helper(&F::operator()));
11891189

1190-
template <std::size_t I, typename T>
1191-
using nth_argument_of = CPP2_TYPEOF(nth_argument_of_helper<I>(std::declval<T>()));
1190+
template <typename T>
1191+
using argument_of = CPP2_TYPEOF(argument_of_helper(std::declval<T>()));
11921192

11931193
// Values
11941194
//
@@ -1206,9 +1206,9 @@ inline constexpr auto is( auto const& x, auto const& value ) -> bool
12061206
// Predicate case
12071207
else if constexpr ( requires{ {value(x)} -> boolean_testable; } ) {
12081208
// defined argument type
1209-
if constexpr (requires { std::declval<nth_argument_of<0, CPP2_TYPEOF(value)>>(); }){
1209+
if constexpr (requires { std::declval<argument_of<CPP2_TYPEOF(value)>>(); }){
12101210
// valid coversion of x to argument type
1211-
if constexpr ( requires { nth_argument_of<0, CPP2_TYPEOF(value)>{x}; }) {
1211+
if constexpr ( requires { argument_of<CPP2_TYPEOF(value)>{x}; }) {
12121212
return value(x); // function-like with valid coversion of argument
12131213
}
12141214
return false; // function-like with invalid coversion of argument
@@ -1513,10 +1513,10 @@ constexpr auto is( std::optional<T> const& x, auto const& value ) -> bool
15131513
// Predicate case
15141514
if constexpr ( requires{ {value(x)} -> boolean_testable; } ) {
15151515
// defined argument type
1516-
if constexpr (requires { std::declval<nth_argument_of<0, CPP2_TYPEOF(value)>>(); }){
1516+
if constexpr (requires { std::declval<argument_of<CPP2_TYPEOF(value)>>(); }){
15171517
// argument type is optional
1518-
if constexpr (requires{is<std::optional>(std::declval<nth_argument_of<0, CPP2_TYPEOF(value)>>());}) {
1519-
using value_type = typename nth_argument_of<0, CPP2_TYPEOF(value)>::value_type; // workaround for gcc-10
1518+
if constexpr (requires{is<std::optional>(std::declval<argument_of<CPP2_TYPEOF(value)>>());}) {
1519+
using value_type = typename argument_of<CPP2_TYPEOF(value)>::value_type; // workaround for gcc-10
15201520
// valid conversion of x::value_type to argument value_type
15211521
if constexpr ( requires { value_type{std::declval<T>()}; }) {
15221522
return value(x); // function-like with valid conversion of argument

0 commit comments

Comments
 (0)