diff --git a/libcudacxx/include/cuda/std/__utility/cmp.h b/libcudacxx/include/cuda/std/__utility/cmp.h index 6aecd0a1e5c..c6d3ad962e9 100644 --- a/libcudacxx/include/cuda/std/__utility/cmp.h +++ b/libcudacxx/include/cuda/std/__utility/cmp.h @@ -20,7 +20,10 @@ # pragma system_header #endif // no system header +#include #include +#include +#include #include #include #include @@ -31,39 +34,45 @@ _CCCL_PUSH_MACROS +_CCCL_DIAG_PUSH +_CCCL_DIAG_SUPPRESS_MSVC(4018) // required cast from signed to unsigned +_CCCL_DIAG_SUPPRESS_MSVC(4388) // required cast from signed to larger unsigned +_CCCL_DIAG_SUPPRESS_MSVC(4389) // signed/unsigned mismatch for == and != + _LIBCUDACXX_BEGIN_NAMESPACE_STD -#if _CCCL_STD_VER > 2017 template -struct _IsSameAsAny : _Or<_IsSame<_Tp, _Up>...> -{}; +using __is_same_as_any = __fold_or<_CCCL_TRAIT(is_same, _Tp, _Up)...>; template -concept __is_safe_integral_cmp = - is_integral_v<_Tp> - && !_IsSameAsAny<_Tp, - bool, - char, - char16_t, - char32_t -# ifndef _LIBCUDACXX_NO_HAS_CHAR8_T - , - char8_t -# endif -# ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS - , - wchar_t -# endif - >::value; - -template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up> +struct __is_safe_integral_cmp + : bool_constant<_CCCL_TRAIT(is_integral, _Tp) + && !__is_same_as_any<_Tp, + bool, + char, + char16_t, + char32_t +#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T + , + char8_t +#endif // _LIBCUDACXX_NO_HAS_CHAR8_T +#ifndef _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS + , + wchar_t +#endif // _LIBCUDACXX_HAS_NO_WIDE_CHARACTERS + >::value> +{}; + +_CCCL_TEMPLATE(class _Tp, class _Up) +_CCCL_REQUIRES(__is_safe_integral_cmp<_Tp>::value _CCCL_AND __is_safe_integral_cmp<_Up>::value) _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept { - if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>) +#if !defined(_CCCL_NO_IF_CONSTEXPR) + if constexpr (_CCCL_TRAIT(is_signed, _Tp) == _CCCL_TRAIT(is_signed, _Up)) { return __t == __u; } - else if constexpr (is_signed_v<_Tp>) + else if constexpr (_CCCL_TRAIT(is_signed, _Tp)) { return __t < 0 ? false : make_unsigned_t<_Tp>(__t) == __u; } @@ -71,22 +80,32 @@ _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept { return __u < 0 ? false : __t == make_unsigned_t<_Up>(__u); } + _CCCL_UNREACHABLE(); +#else // ^^^ !_CCCL_NO_IF_CONSTEXPR ^^^ / vvv _CCCL_NO_IF_CONSTEXPR vvv + return ((_CCCL_TRAIT(is_signed, _Tp) == _CCCL_TRAIT(is_signed, _Up)) + ? (__t == __u) + : (_CCCL_TRAIT(is_signed, _Tp) ? (__t < 0 ? false : make_unsigned_t<_Tp>(__t) == __u) + : (__u < 0 ? false : __t == make_unsigned_t<_Up>(__u)))); +#endif // _CCCL_NO_IF_CONSTEXPR } -template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up> +_CCCL_TEMPLATE(class _Tp, class _Up) +_CCCL_REQUIRES(__is_safe_integral_cmp<_Tp>::value _CCCL_AND __is_safe_integral_cmp<_Up>::value) _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_not_equal(_Tp __t, _Up __u) noexcept { return !_CUDA_VSTD::cmp_equal(__t, __u); } -template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up> +_CCCL_TEMPLATE(class _Tp, class _Up) +_CCCL_REQUIRES(__is_safe_integral_cmp<_Tp>::value _CCCL_AND __is_safe_integral_cmp<_Up>::value) _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept { - if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>) +#if !defined(_CCCL_NO_IF_CONSTEXPR) + if constexpr (_CCCL_TRAIT(is_signed, _Tp) == _CCCL_TRAIT(is_signed, _Up)) { return __t < __u; } - else if constexpr (is_signed_v<_Tp>) + else if constexpr (_CCCL_TRAIT(is_signed, _Tp)) { return __t < 0 ? true : make_unsigned_t<_Tp>(__t) < __u; } @@ -94,36 +113,48 @@ _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept { return __u < 0 ? false : __t < make_unsigned_t<_Up>(__u); } + _CCCL_UNREACHABLE(); +#else // ^^^ !_CCCL_NO_IF_CONSTEXPR ^^^ / vvv _CCCL_NO_IF_CONSTEXPR vvv + return ((_CCCL_TRAIT(is_signed, _Tp) == _CCCL_TRAIT(is_signed, _Up)) + ? (__t < __u) + : (_CCCL_TRAIT(is_signed, _Tp) ? (__t < 0 ? true : make_unsigned_t<_Tp>(__t) < __u) + : (__u < 0 ? false : __t < make_unsigned_t<_Up>(__u)))); +#endif // _CCCL_NO_IF_CONSTEXPR } -template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up> +_CCCL_TEMPLATE(class _Tp, class _Up) +_CCCL_REQUIRES(__is_safe_integral_cmp<_Tp>::value _CCCL_AND __is_safe_integral_cmp<_Up>::value) _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_greater(_Tp __t, _Up __u) noexcept { return _CUDA_VSTD::cmp_less(__u, __t); } -template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up> +_CCCL_TEMPLATE(class _Tp, class _Up) +_CCCL_REQUIRES(__is_safe_integral_cmp<_Tp>::value _CCCL_AND __is_safe_integral_cmp<_Up>::value) _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_less_equal(_Tp __t, _Up __u) noexcept { return !_CUDA_VSTD::cmp_greater(__t, __u); } -template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up> +_CCCL_TEMPLATE(class _Tp, class _Up) +_CCCL_REQUIRES(__is_safe_integral_cmp<_Tp>::value _CCCL_AND __is_safe_integral_cmp<_Up>::value) _LIBCUDACXX_HIDE_FROM_ABI constexpr bool cmp_greater_equal(_Tp __t, _Up __u) noexcept { return !_CUDA_VSTD::cmp_less(__t, __u); } -template <__is_safe_integral_cmp _Tp, __is_safe_integral_cmp _Up> +_CCCL_TEMPLATE(class _Tp, class _Up) +_CCCL_REQUIRES(__is_safe_integral_cmp<_Tp>::value _CCCL_AND __is_safe_integral_cmp<_Up>::value) _LIBCUDACXX_HIDE_FROM_ABI constexpr bool in_range(_Up __u) noexcept { return _CUDA_VSTD::cmp_less_equal(__u, numeric_limits<_Tp>::max()) && _CUDA_VSTD::cmp_greater_equal(__u, numeric_limits<_Tp>::min()); } -#endif // _CCCL_STD_VER > 2017 _LIBCUDACXX_END_NAMESPACE_STD +_CCCL_DIAG_POP + _CCCL_POP_MACROS #endif // _LIBCUDACXX___UTILITY_CMP_H diff --git a/libcudacxx/include/cuda/std/version b/libcudacxx/include/cuda/std/version index 0762976d0d9..3b973a8bfab 100644 --- a/libcudacxx/include/cuda/std/version +++ b/libcudacxx/include/cuda/std/version @@ -43,11 +43,12 @@ # define __cccl_lib_exchange_function 201304L # define __cccl_lib_expected 202211L // # define __cccl_lib_generic_associative_lookup 201304L -# define __cccl_lib_integer_sequence 201304L -# define __cccl_lib_integral_constant_callable 201304L -# define __cccl_lib_is_final 201402L -# define __cccl_lib_is_null_pointer 201309L -# define __cccl_lib_make_reverse_iterator 201402L +# define __cccl_lib_integer_sequence 201304L +# define __cccl_lib_integer_comparison_functions 202002L +# define __cccl_lib_integral_constant_callable 201304L +# define __cccl_lib_is_final 201402L +# define __cccl_lib_is_null_pointer 201309L +# define __cccl_lib_make_reverse_iterator 201402L // # define __cccl_lib_make_unique 201304L # if !_CCCL_COMPILER(MSVC) || _CCCL_STD_VER >= 2020 # define __cccl_lib_mdspan 202207L @@ -178,7 +179,6 @@ // # define __cccl_lib_format 202106L // # define __cccl_lib_generic_unordered_lookup 201811L // # define __cccl_lib_int_pow2 202002L -// # define __cccl_lib_integer_comparison_functions 202002L // # define __cccl_lib_interpolate 201902L # ifdef _CCCL_BUILTIN_IS_CONSTANT_EVALUATED # define __cccl_lib_is_constant_evaluated 201811L diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_equal/cmp_equal.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_equal/cmp_equal.pass.cpp index 4d715ff6940..3d0c0e8757b 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_equal/cmp_equal.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_equal/cmp_equal.pass.cpp @@ -7,12 +7,10 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // // template -// constexpr bool cmp_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_equal(T t, U u) noexcept; #include #include @@ -24,28 +22,17 @@ template struct Tuple { - T min; - T max; - T mid; - __host__ __device__ constexpr Tuple() - { - min = cuda::std::numeric_limits::min(); - max = cuda::std::numeric_limits::max(); - if constexpr (cuda::std::is_signed_v) - { - mid = T(-1); - } - else - { - mid = max >> 1; - } - } + T min = cuda::std::numeric_limits::min(); + T max = cuda::std::numeric_limits::max(); + T mid = cuda::std::is_signed::value ? T(-1) : max >> 1; + + __host__ __device__ constexpr Tuple() noexcept {} }; template -__host__ __device__ constexpr void test_cmp_equal1() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test1() { - constexpr Tuple tup; + constexpr Tuple tup{}; assert(cuda::std::cmp_equal(T(0), T(0))); assert(cuda::std::cmp_equal(T(10), T(10))); assert(cuda::std::cmp_equal(tup.min, tup.min)); @@ -68,10 +55,10 @@ __host__ __device__ constexpr void test_cmp_equal1() } template -__host__ __device__ constexpr void test_cmp_equal2() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test2() { - constexpr Tuple ttup; - constexpr Tuple utup; + constexpr Tuple ttup{}; + constexpr Tuple utup{}; assert(cuda::std::cmp_equal(T(0), U(0))); assert(cuda::std::cmp_equal(T(10), U(10))); assert(!cuda::std::cmp_equal(T(0), U(1))); @@ -82,44 +69,42 @@ __host__ __device__ constexpr void test_cmp_equal2() assert(!cuda::std::cmp_equal(utup.min, ttup.max)); } -template -__host__ __device__ constexpr void test1(const cuda::std::tuple&) -{ - (test_cmp_equal1(), ...); -} - -template -__host__ __device__ constexpr void test2_impl(const cuda::std::tuple&) +template +__host__ __device__ TEST_CONSTEXPR_CXX14 void test() { - (test_cmp_equal2(), ...); -} - -template -__host__ __device__ constexpr void test2(const cuda::std::tuple&, const UTuple& utuple) -{ - (test2_impl(utuple), ...); + test1(); +#ifndef TEST_HAS_NO_INT128_T + test2(); + test2(); +#endif // TEST_HAS_NO_INT128_T + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); } -__host__ __device__ constexpr bool test() +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - cuda::std::tuple< #ifndef TEST_HAS_NO_INT128_T - __int128_t, - __uint128_t, -#endif - unsigned long long, - long long, - unsigned long, - long, - unsigned int, - int, - unsigned short, - short, - unsigned char, - signed char> - types; - test1(types); - test2(types, types); + test<__int128_t>(); + test<__uint128_t>(); +#endif // TEST_HAS_NO_INT128_T + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); return true; } @@ -127,6 +112,8 @@ int main(int, char**) { ASSERT_NOEXCEPT(cuda::std::cmp_equal(0, 0)); test(); - static_assert(test()); +#if TEST_STD_VER >= 2014 + static_assert(test(), ""); +#endif // TEST_STD_VER >= 2014 return 0; } diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater/cmp_greater.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater/cmp_greater.pass.cpp index 5ac4ed3cd0d..5c816949a69 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater/cmp_greater.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater/cmp_greater.pass.cpp @@ -6,11 +6,9 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // -// constexpr bool cmp_greater(T t, U u) noexcept; // C++20 +// constexpr bool cmp_greater(T t, U u) noexcept; #include #include @@ -22,28 +20,17 @@ template struct Tuple { - T min; - T max; - T mid; - __host__ __device__ constexpr Tuple() - { - min = cuda::std::numeric_limits::min(); - max = cuda::std::numeric_limits::max(); - if constexpr (cuda::std::is_signed_v) - { - mid = T(-1); - } - else - { - mid = max >> 1; - } - } + T min = cuda::std::numeric_limits::min(); + T max = cuda::std::numeric_limits::max(); + T mid = cuda::std::is_signed::value ? T(-1) : max >> 1; + + __host__ __device__ constexpr Tuple() noexcept {} }; template -__host__ __device__ constexpr void test_cmp_greater1() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test1() { - constexpr Tuple tup; + constexpr Tuple tup{}; assert(!cuda::std::cmp_greater(T(0), T(1))); assert(!cuda::std::cmp_greater(T(1), T(2))); assert(!cuda::std::cmp_greater(tup.min, tup.max)); @@ -59,57 +46,55 @@ __host__ __device__ constexpr void test_cmp_greater1() assert(cuda::std::cmp_greater(tup.max, 1)); assert(cuda::std::cmp_greater(1, tup.min)); assert(!cuda::std::cmp_greater(T(-1), T(-1))); - assert(cuda::std::cmp_greater(-2, tup.min) == cuda::std::is_signed_v); - assert(!cuda::std::cmp_greater(tup.min, -2) == cuda::std::is_signed_v); + assert(cuda::std::cmp_greater(-2, tup.min) == cuda::std::is_signed::value); + assert(!cuda::std::cmp_greater(tup.min, -2) == cuda::std::is_signed::value); assert(!cuda::std::cmp_greater(-2, tup.max)); assert(cuda::std::cmp_greater(tup.max, -2)); } template -__host__ __device__ constexpr void test_cmp_greater2() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test2() { assert(!cuda::std::cmp_greater(T(0), U(1))); assert(cuda::std::cmp_greater(T(1), U(0))); } -template -__host__ __device__ constexpr void test1(const cuda::std::tuple&) -{ - (test_cmp_greater1(), ...); -} - -template -__host__ __device__ constexpr void test2_impl(const cuda::std::tuple&) +template +__host__ __device__ TEST_CONSTEXPR_CXX14 void test() { - (test_cmp_greater2(), ...); -} - -template -__host__ __device__ constexpr void test2(const cuda::std::tuple&, const UTuple& utuple) -{ - (test2_impl(utuple), ...); + test1(); +#ifndef TEST_HAS_NO_INT128_T + test2(); + test2(); +#endif // TEST_HAS_NO_INT128_T + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); } -__host__ __device__ constexpr bool test() +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - cuda::std::tuple< #ifndef TEST_HAS_NO_INT128_T - __int128_t, - __uint128_t, -#endif - unsigned long long, - long long, - unsigned long, - long, - unsigned int, - int, - unsigned short, - short, - unsigned char, - signed char> - types; - test1(types); - test2(types, types); + test<__int128_t>(); + test<__uint128_t>(); +#endif // TEST_HAS_NO_INT128_T + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); return true; } @@ -117,6 +102,8 @@ int main(int, char**) { ASSERT_NOEXCEPT(cuda::std::cmp_greater(1, 0)); test(); - static_assert(test()); +#if TEST_STD_VER >= 2014 + static_assert(test(), ""); +#endif // TEST_STD_VER >= 2014 return 0; } diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater_equal/cmp_greater_equal.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater_equal/cmp_greater_equal.pass.cpp index 38405a7a305..1c1d7729d2e 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater_equal/cmp_greater_equal.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_greater_equal/cmp_greater_equal.pass.cpp @@ -6,11 +6,9 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // -// constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_greater_equal(T t, U u) noexcept; #include #include @@ -22,28 +20,17 @@ template struct Tuple { - T min; - T max; - T mid; - __host__ __device__ constexpr Tuple() - { - min = cuda::std::numeric_limits::min(); - max = cuda::std::numeric_limits::max(); - if constexpr (cuda::std::is_signed_v) - { - mid = T(-1); - } - else - { - mid = max >> 1; - } - } + T min = cuda::std::numeric_limits::min(); + T max = cuda::std::numeric_limits::max(); + T mid = cuda::std::is_signed::value ? T(-1) : max >> 1; + + __host__ __device__ constexpr Tuple() noexcept {} }; template -__host__ __device__ constexpr void test_cmp_greater_equal1() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test1() { - constexpr Tuple tup; + constexpr Tuple tup{}; assert(!cuda::std::cmp_greater_equal(T(0), T(1))); assert(!cuda::std::cmp_greater_equal(T(1), T(2))); assert(!cuda::std::cmp_greater_equal(tup.min, tup.max)); @@ -59,14 +46,14 @@ __host__ __device__ constexpr void test_cmp_greater_equal1() assert(cuda::std::cmp_greater_equal(tup.max, 1)); assert(cuda::std::cmp_greater_equal(1, tup.min)); assert(cuda::std::cmp_greater_equal(T(-1), T(-1))); - assert(cuda::std::cmp_greater_equal(-2, tup.min) == cuda::std::is_signed_v); - assert(cuda::std::cmp_greater_equal(tup.min, -2) == cuda::std::is_unsigned_v); + assert(cuda::std::cmp_greater_equal(-2, tup.min) == cuda::std::is_signed::value); + assert(cuda::std::cmp_greater_equal(tup.min, -2) == cuda::std::is_unsigned::value); assert(!cuda::std::cmp_greater_equal(-2, tup.max)); assert(cuda::std::cmp_greater_equal(tup.max, -2)); } template -__host__ __device__ constexpr void test_cmp_greater_equal2() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test2() { assert(!cuda::std::cmp_greater_equal(T(0), U(1))); assert(cuda::std::cmp_greater_equal(T(1), U(0))); @@ -74,44 +61,42 @@ __host__ __device__ constexpr void test_cmp_greater_equal2() assert(cuda::std::cmp_greater_equal(T(1), U(1))); } -template -__host__ __device__ constexpr void test1(const cuda::std::tuple&) -{ - (test_cmp_greater_equal1(), ...); -} - -template -__host__ __device__ constexpr void test2_impl(const cuda::std::tuple&) +template +__host__ __device__ TEST_CONSTEXPR_CXX14 void test() { - (test_cmp_greater_equal2(), ...); -} - -template -__host__ __device__ constexpr void test2(const cuda::std::tuple&, const UTuple& utuple) -{ - (test2_impl(utuple), ...); + test1(); +#ifndef TEST_HAS_NO_INT128_T + test2(); + test2(); +#endif // TEST_HAS_NO_INT128_T + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); } -__host__ __device__ constexpr bool test() +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - cuda::std::tuple< #ifndef TEST_HAS_NO_INT128_T - __int128_t, - __uint128_t, -#endif - unsigned long long, - long long, - unsigned long, - long, - unsigned int, - int, - unsigned short, - short, - unsigned char, - signed char> - types; - test1(types); - test2(types, types); + test<__int128_t>(); + test<__uint128_t>(); +#endif // TEST_HAS_NO_INT128_T + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); return true; } @@ -119,6 +104,8 @@ int main(int, char**) { ASSERT_NOEXCEPT(cuda::std::cmp_greater_equal(1, 0)); test(); - static_assert(test()); +#if TEST_STD_VER >= 2014 + static_assert(test(), ""); +#endif // TEST_STD_VER >= 2014 return 0; } diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less/cmp_less.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less/cmp_less.pass.cpp index 158c07a0c42..9ec369c28a3 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less/cmp_less.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less/cmp_less.pass.cpp @@ -6,12 +6,10 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // // template -// constexpr bool cmp_less(T t, U u) noexcept; // C++20 +// constexpr bool cmp_less(T t, U u) noexcept; #include #include @@ -23,28 +21,17 @@ template struct Tuple { - T min; - T max; - T mid; - __host__ __device__ constexpr Tuple() - { - min = cuda::std::numeric_limits::min(); - max = cuda::std::numeric_limits::max(); - if constexpr (cuda::std::is_signed_v) - { - mid = T(-1); - } - else - { - mid = max >> 1; - } - } + T min = cuda::std::numeric_limits::min(); + T max = cuda::std::numeric_limits::max(); + T mid = cuda::std::is_signed::value ? T(-1) : max >> 1; + + __host__ __device__ constexpr Tuple() noexcept {} }; template -__host__ __device__ constexpr void test_cmp_less1() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test1() { - constexpr Tuple tup; + constexpr Tuple tup{}; assert(cuda::std::cmp_less(T(0), T(1))); assert(cuda::std::cmp_less(T(1), T(2))); assert(cuda::std::cmp_less(tup.min, tup.max)); @@ -60,57 +47,55 @@ __host__ __device__ constexpr void test_cmp_less1() assert(!cuda::std::cmp_less(tup.max, 1)); assert(!cuda::std::cmp_less(1, tup.min)); assert(!cuda::std::cmp_less(T(-1), T(-1))); - assert(!cuda::std::cmp_less(-2, tup.min) == cuda::std::is_signed_v); - assert(cuda::std::cmp_less(tup.min, -2) == cuda::std::is_signed_v); + assert(!cuda::std::cmp_less(-2, tup.min) == cuda::std::is_signed::value); + assert(cuda::std::cmp_less(tup.min, -2) == cuda::std::is_signed::value); assert(cuda::std::cmp_less(-2, tup.max)); assert(!cuda::std::cmp_less(tup.max, -2)); } template -__host__ __device__ constexpr void test_cmp_less2() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test2() { assert(cuda::std::cmp_less(T(0), U(1))); assert(!cuda::std::cmp_less(T(1), U(0))); } -template -__host__ __device__ constexpr void test1(const cuda::std::tuple&) -{ - (test_cmp_less1(), ...); -} - -template -__host__ __device__ constexpr void test2_impl(const cuda::std::tuple&) +template +__host__ __device__ TEST_CONSTEXPR_CXX14 void test() { - (test_cmp_less2(), ...); -} - -template -__host__ __device__ constexpr void test2(const cuda::std::tuple&, const UTuple& utuple) -{ - (test2_impl(utuple), ...); + test1(); +#ifndef TEST_HAS_NO_INT128_T + test2(); + test2(); +#endif // TEST_HAS_NO_INT128_T + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); } -__host__ __device__ constexpr bool test() +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - cuda::std::tuple< #ifndef TEST_HAS_NO_INT128_T - __int128_t, - __uint128_t, -#endif - unsigned long long, - long long, - unsigned long, - long, - unsigned int, - int, - unsigned short, - short, - unsigned char, - signed char> - types; - test1(types); - test2(types, types); + test<__int128_t>(); + test<__uint128_t>(); +#endif // TEST_HAS_NO_INT128_T + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); return true; } @@ -118,6 +103,8 @@ int main(int, char**) { ASSERT_NOEXCEPT(cuda::std::cmp_less(0, 1)); test(); - static_assert(test()); +#if TEST_STD_VER >= 2014 + static_assert(test(), ""); +#endif // TEST_STD_VER >= 2014 return 0; } diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less_equal/cmp_less_equal.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less_equal/cmp_less_equal.pass.cpp index cce292b20e2..a33a248a493 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less_equal/cmp_less_equal.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_less_equal/cmp_less_equal.pass.cpp @@ -6,11 +6,9 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // -// constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_less_equal(T t, U u) noexcept; #include #include @@ -22,28 +20,17 @@ template struct Tuple { - T min; - T max; - T mid; - __host__ __device__ constexpr Tuple() - { - min = cuda::std::numeric_limits::min(); - max = cuda::std::numeric_limits::max(); - if constexpr (cuda::std::is_signed_v) - { - mid = T(-1); - } - else - { - mid = max >> 1; - } - } + T min = cuda::std::numeric_limits::min(); + T max = cuda::std::numeric_limits::max(); + T mid = cuda::std::is_signed::value ? T(-1) : max >> 1; + + __host__ __device__ constexpr Tuple() noexcept {} }; template -__host__ __device__ constexpr void test_cmp_less_equal1() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test1() { - constexpr Tuple tup; + constexpr Tuple tup{}; assert(cuda::std::cmp_less_equal(T(0), T(0))); assert(cuda::std::cmp_less_equal(T(0), T(1))); assert(cuda::std::cmp_less_equal(tup.min, tup.max)); @@ -59,58 +46,56 @@ __host__ __device__ constexpr void test_cmp_less_equal1() assert(!cuda::std::cmp_less_equal(tup.max, 1)); assert(!cuda::std::cmp_less_equal(1, tup.min)); assert(cuda::std::cmp_less_equal(T(-1), T(-1))); - assert(!cuda::std::cmp_less_equal(-2, tup.min) == cuda::std::is_signed_v); - assert(cuda::std::cmp_less_equal(tup.min, -2) == cuda::std::is_signed_v); + assert(!cuda::std::cmp_less_equal(-2, tup.min) == cuda::std::is_signed::value); + assert(cuda::std::cmp_less_equal(tup.min, -2) == cuda::std::is_signed::value); assert(cuda::std::cmp_less_equal(-2, tup.max)); assert(!cuda::std::cmp_less_equal(tup.max, -2)); } template -__host__ __device__ constexpr void test_cmp_less_equal2() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test2() { assert(cuda::std::cmp_less_equal(T(0), U(1))); assert(cuda::std::cmp_less_equal(T(0), U(0))); assert(!cuda::std::cmp_less_equal(T(1), U(0))); } -template -__host__ __device__ constexpr void test1(const cuda::std::tuple&) -{ - (test_cmp_less_equal1(), ...); -} - -template -__host__ __device__ constexpr void test2_impl(const cuda::std::tuple&) +template +__host__ __device__ TEST_CONSTEXPR_CXX14 void test() { - (test_cmp_less_equal2(), ...); -} - -template -__host__ __device__ constexpr void test2(const cuda::std::tuple&, const UTuple& utuple) -{ - (test2_impl(utuple), ...); + test1(); +#ifndef TEST_HAS_NO_INT128_T + test2(); + test2(); +#endif // TEST_HAS_NO_INT128_T + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); } -__host__ __device__ constexpr bool test() +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - cuda::std::tuple< #ifndef TEST_HAS_NO_INT128_T - __int128_t, - __uint128_t, -#endif - unsigned long long, - long long, - unsigned long, - long, - unsigned int, - int, - unsigned short, - short, - unsigned char, - signed char> - types; - test1(types); - test2(types, types); + test<__int128_t>(); + test<__uint128_t>(); +#endif // TEST_HAS_NO_INT128_T + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); return true; } @@ -118,6 +103,8 @@ int main(int, char**) { ASSERT_NOEXCEPT(cuda::std::cmp_less_equal(0, 1)); test(); - static_assert(test()); +#if TEST_STD_VER >= 2014 + static_assert(test(), ""); +#endif // TEST_STD_VER >= 2014 return 0; } diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_not_equal/cmp_not_equal.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_not_equal/cmp_not_equal.pass.cpp index c53781c23ba..383a4229d30 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_not_equal/cmp_not_equal.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.cmp_not_equal/cmp_not_equal.pass.cpp @@ -6,12 +6,10 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // // template -// constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_not_equal(T t, U u) noexcept; #include #include @@ -23,28 +21,17 @@ template struct Tuple { - T min; - T max; - T mid; - __host__ __device__ constexpr Tuple() - { - min = cuda::std::numeric_limits::min(); - max = cuda::std::numeric_limits::max(); - if constexpr (cuda::std::is_signed_v) - { - mid = T(-1); - } - else - { - mid = max >> 1; - } - } + T min = cuda::std::numeric_limits::min(); + T max = cuda::std::numeric_limits::max(); + T mid = cuda::std::is_signed::value ? T(-1) : max >> 1; + + __host__ __device__ constexpr Tuple() noexcept {} }; template -__host__ __device__ constexpr void test_cmp_not_equal1() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test1() { - constexpr Tuple tup; + TEST_CONSTEXPR_CXX14 Tuple tup{}; assert(!cuda::std::cmp_not_equal(T(0), T(0))); assert(!cuda::std::cmp_not_equal(T(10), T(10))); assert(!cuda::std::cmp_not_equal(tup.min, tup.min)); @@ -66,10 +53,10 @@ __host__ __device__ constexpr void test_cmp_not_equal1() } template -__host__ __device__ constexpr void test_cmp_not_equal2() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test2() { - constexpr Tuple ttup; - constexpr Tuple utup; + TEST_CONSTEXPR_CXX14 Tuple ttup; + TEST_CONSTEXPR_CXX14 Tuple utup; assert(!cuda::std::cmp_not_equal(T(0), U(0))); assert(!cuda::std::cmp_not_equal(T(10), U(10))); assert(cuda::std::cmp_not_equal(T(0), U(1))); @@ -80,44 +67,42 @@ __host__ __device__ constexpr void test_cmp_not_equal2() assert(cuda::std::cmp_not_equal(utup.min, ttup.max)); } -template -__host__ __device__ constexpr void test1(const cuda::std::tuple&) -{ - (test_cmp_not_equal1(), ...); -} - -template -__host__ __device__ constexpr void test2_impl(const cuda::std::tuple&) +template +__host__ __device__ TEST_CONSTEXPR_CXX14 void test() { - (test_cmp_not_equal2(), ...); -} - -template -__host__ __device__ constexpr void test2(const cuda::std::tuple&, const UTuple& utuple) -{ - (test2_impl(utuple), ...); + test1(); +#ifndef TEST_HAS_NO_INT128_T + test2(); + test2(); +#endif // TEST_HAS_NO_INT128_T + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); + test2(); } -__host__ __device__ constexpr bool test() +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - cuda::std::tuple< #ifndef TEST_HAS_NO_INT128_T - __int128_t, - __uint128_t, -#endif - unsigned long long, - long long, - unsigned long, - long, - unsigned int, - int, - unsigned short, - short, - unsigned char, - signed char> - types; - test1(types); - test2(types, types); + test<__int128_t>(); + test<__uint128_t>(); +#endif // TEST_HAS_NO_INT128_T + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); return true; } @@ -125,6 +110,8 @@ int main(int, char**) { ASSERT_NOEXCEPT(cuda::std::cmp_not_equal(0, 0)); test(); - static_assert(test()); +#if TEST_STD_VER >= 2014 + static_assert(test(), ""); +#endif // TEST_STD_VER >= 2014 return 0; } diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.fail.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.fail.cpp index 8cdc1d755a0..2fab113df47 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.fail.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.fail.cpp @@ -6,30 +6,28 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // // template -// constexpr bool cmp_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_equal(T t, U u) noexcept; // template -// constexpr bool cmp_not_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_not_equal(T t, U u) noexcept; // template -// constexpr bool cmp_less(T t, U u) noexcept; // C++20 +// constexpr bool cmp_less(T t, U u) noexcept; // template -// constexpr bool cmp_less_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_less_equal(T t, U u) noexcept; // template -// constexpr bool cmp_greater(T t, U u) noexcept; // C++20 +// constexpr bool cmp_greater(T t, U u) noexcept; // template -// constexpr bool cmp_greater_equal(T t, U u) noexcept; // C++20 +// constexpr bool cmp_greater_equal(T t, U u) noexcept; // template -// constexpr bool in_range(T t) noexcept; // C++20 +// constexpr bool in_range(T t) noexcept; #include #include @@ -66,7 +64,7 @@ struct EmptyT {}; template -__host__ __device__ constexpr void test() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test() { cuda::std::cmp_equal(T(), T()); // expected-error 10-11 {{no matching function for call to 'cmp_equal'}} cuda::std::cmp_equal(T(), int()); // expected-error 10-11 {{no matching function for call to 'cmp_equal'}} @@ -94,7 +92,7 @@ __host__ __device__ constexpr void test() } #ifndef TEST_HAS_NO_CHAR8_T template -__host__ __device__ constexpr void test_char8t() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test_char8t() { cuda::std::cmp_equal(T(), T()); // expected-error 1 {{no matching function for call to 'cmp_equal'}} cuda::std::cmp_equal(T(), int()); // expected-error 1 {{no matching function for call to 'cmp_equal'}} @@ -120,7 +118,7 @@ __host__ __device__ constexpr void test_char8t() #endif // TEST_HAS_NO_CHAR8_T template -__host__ __device__ constexpr void test_uchars() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test_uchars() { cuda::std::cmp_equal(T(), T()); // expected-error 2 {{no matching function for call to 'cmp_equal'}} cuda::std::cmp_equal(T(), int()); // expected-error 2 {{no matching function for call to 'cmp_equal'}} diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.in_range/in_range.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.in_range/in_range.pass.cpp index 634fee7b584..73bb106f77f 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.in_range/in_range.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/utility.intcmp/intcmp.in_range/in_range.pass.cpp @@ -6,12 +6,10 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17 - // // template -// constexpr bool in_range(T t) noexcept; // C++20 +// constexpr bool in_range(T t) noexcept; #include #include @@ -24,28 +22,17 @@ template struct Tuple { - T min; - T max; - T mid; - __host__ __device__ constexpr Tuple() - { - min = cuda::std::numeric_limits::min(); - max = cuda::std::numeric_limits::max(); - if constexpr (cuda::std::is_signed_v) - { - mid = T(-1); - } - else - { - mid = max >> 1; - } - } + T min = cuda::std::numeric_limits::min(); + T max = cuda::std::numeric_limits::max(); + T mid = cuda::std::is_signed::value ? T(-1) : max >> 1; + + __host__ __device__ constexpr Tuple() noexcept {} }; template -__host__ __device__ constexpr void test_in_range1() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test_in_range1() { - constexpr Tuple tup; + constexpr Tuple tup{}; assert(cuda::std::in_range(tup.min)); assert(cuda::std::in_range(tup.min + 1)); assert(cuda::std::in_range(tup.max)); @@ -55,10 +42,10 @@ __host__ __device__ constexpr void test_in_range1() assert(cuda::std::in_range(tup.mid + 1)); } -__host__ __device__ constexpr void test_in_range() +__host__ __device__ TEST_CONSTEXPR_CXX14 void test_in_range() { - constexpr Tuple utup8; - constexpr Tuple stup8; + constexpr Tuple utup8{}; + constexpr Tuple stup8{}; assert(!cuda::std::in_range(utup8.max)); assert(cuda::std::in_range(utup8.max)); assert(!cuda::std::in_range(stup8.min)); @@ -67,32 +54,23 @@ __host__ __device__ constexpr void test_in_range() assert(!cuda::std::in_range(-1)); } -template -__host__ __device__ constexpr void test1(const cuda::std::tuple&) +__host__ __device__ TEST_CONSTEXPR_CXX14 bool test() { - (test_in_range1(), ...); -} - -__host__ __device__ constexpr bool test() -{ - cuda::std::tuple< -#ifndef TEST_HAS_NO_INT128_T - __int128_t, - __uint128_t, -#endif - unsigned long long, - long long, - unsigned long, - long, - unsigned int, - int, - unsigned short, - short, - unsigned char, - signed char> - types; - test1(types); test_in_range(); +#ifndef TEST_HAS_NO_INT128_T + test_in_range1<__int128_t>(); + test_in_range1<__uint128_t>(); +#endif // TEST_HAS_NO_INT128_T + test_in_range1(); + test_in_range1(); + test_in_range1(); + test_in_range1(); + test_in_range1(); + test_in_range1(); + test_in_range1(); + test_in_range1(); + test_in_range1(); + test_in_range1(); return true; } @@ -100,6 +78,8 @@ int main(int, char**) { ASSERT_NOEXCEPT(cuda::std::in_range(-1)); test(); - static_assert(test()); +#if TEST_STD_VER >= 2014 + static_assert(test(), ""); +#endif // TEST_STD_VER >= 2014 return 0; }