Skip to content

Commit 13137b4

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 13137b4

7 files changed

+21
-21
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

regression-tests/test-results/apple-clang-14/pure2-as-cast-arithetic-types-bigger-to-smaller.cpp.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
In file included from pure2-as-cast-arithetic-types-bigger-to-smaller.cpp:7:
2-
../../../include/cpp2util.h:1809:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<unsigned char, unsigned short &&>' "'as' does not allow unsafe narrowing conversions - if you're sure you want this, use `unsafe_narrow<T>()` to force the conversion"
2+
../../../include/cpp2util.h:1821:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<unsigned char, unsigned short &&>' "'as' does not allow unsafe narrowing conversions - if you're sure you want this, use `unsafe_narrow<T>()` to force the conversion"
33
static_assert(
44
^
55
pure2-as-cast-arithetic-types-bigger-to-smaller.cpp:19:19: note: in instantiation of function template specialization 'cpp2::as_<unsigned char, unsigned short>' requested here

regression-tests/test-results/apple-clang-14/pure2-as-cast-bigger-signed-to-smaller-unsigned.cpp.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
In file included from pure2-as-cast-bigger-signed-to-smaller-unsigned.cpp:7:
2-
../../../include/cpp2util.h:1809:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<unsigned char, short &&>' "'as' does not allow unsafe narrowing conversions - if you're sure you want this, use `unsafe_narrow<T>()` to force the conversion"
2+
../../../include/cpp2util.h:1821:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<unsigned char, short &&>' "'as' does not allow unsafe narrowing conversions - if you're sure you want this, use `unsafe_narrow<T>()` to force the conversion"
33
static_assert(
44
^
55
pure2-as-cast-bigger-signed-to-smaller-unsigned.cpp:19:19: note: in instantiation of function template specialization 'cpp2::as_<unsigned char, short>' requested here

regression-tests/test-results/apple-clang-14/pure2-as-cast-class-to-unrelated-class.cpp.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
In file included from pure2-as-cast-class-to-unrelated-class.cpp:7:
2-
../../../include/cpp2util.h:1815:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<A, B &&>' "No safe 'as' cast available - please check your cast"
2+
../../../include/cpp2util.h:1827:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<A, B &&>' "No safe 'as' cast available - please check your cast"
33
static_assert(
44
^
55
pure2-as-cast-class-to-unrelated-class.cpp2:12:19: note: in instantiation of function template specialization 'cpp2::as_<A, B>' requested here

regression-tests/test-results/apple-clang-14/pure2-as-cast-custom-class-to-string.cpp.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
In file included from pure2-as-cast-custom-class-to-string.cpp:7:
2-
../../../include/cpp2util.h:1815:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<std::string, A &&>' "No safe 'as' cast available - please check your cast"
2+
../../../include/cpp2util.h:1827:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<std::string, A &&>' "No safe 'as' cast available - please check your cast"
33
static_assert(
44
^
55
pure2-as-cast-custom-class-to-string.cpp2:11:19: note: in instantiation of function template specialization 'cpp2::as_<std::string, A>' requested here

regression-tests/test-results/apple-clang-14/pure2-as-cast-double-to-int.cpp.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
In file included from pure2-as-cast-double-to-int.cpp:7:
2-
../../../include/cpp2util.h:1809:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<int, double &&>' "'as' does not allow unsafe narrowing conversions - if you're sure you want this, use `unsafe_narrow<T>()` to force the conversion"
2+
../../../include/cpp2util.h:1821:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<int, double &&>' "'as' does not allow unsafe narrowing conversions - if you're sure you want this, use `unsafe_narrow<T>()` to force the conversion"
33
static_assert(
44
^
55
pure2-as-cast-double-to-int.cpp:19:19: note: in instantiation of function template specialization 'cpp2::as_<int, double>' requested here

regression-tests/test-results/apple-clang-14/pure2-as-cast-to-unrelated-type.cpp.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
In file included from pure2-as-cast-to-unrelated-type.cpp:7:
2-
../../../include/cpp2util.h:1815:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<A, int &>' "No safe 'as' cast available - please check your cast"
2+
../../../include/cpp2util.h:1827:9: error: static_assert failed due to requirement 'program_violates_type_safety_guarantee<A, int &>' "No safe 'as' cast available - please check your cast"
33
static_assert(
44
^
55
pure2-as-cast-to-unrelated-type.cpp2:5:19: note: in instantiation of function template specialization 'cpp2::as_<A, int &>' requested here

0 commit comments

Comments
 (0)