Skip to content

Commit 217ba2a

Browse files
misccodavebayer
authored andcommitted
Use _CCCL_REQUIRES_EXPR in test code (NVIDIA#3954)
1 parent b84a6ff commit 217ba2a

File tree

22 files changed

+47
-177
lines changed

22 files changed

+47
-177
lines changed

libcudacxx/test/libcudacxx/std/concepts/concepts.lang/concept.default.init/default_initializable.verify.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
#include "test_macros.h"
1919

2020
template <class T>
21-
_CCCL_CONCEPT_FRAGMENT(brace_initializable_, requires()(T{}));
22-
23-
template <class T>
24-
_CCCL_CONCEPT brace_initializable = _CCCL_FRAGMENT(brace_initializable_, T);
21+
_CCCL_CONCEPT brace_initializable = _CCCL_REQUIRES_EXPR((T))((T{}));
2522

2623
__host__ __device__ void test()
2724
{

libcudacxx/test/libcudacxx/std/iterators/iterator.requirements/indirectcallable/indirectinvocable/indirect_result_t.compile.pass.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ static_assert(cuda::std::same_as<cuda::std::indirect_result_t<long S::*, S*>, lo
2323
static_assert(cuda::std::same_as<cuda::std::indirect_result_t<S && (S::*) (), S*>, S&&>, "");
2424
static_assert(cuda::std::same_as<cuda::std::indirect_result_t<int S::* (S::*) (int) const, S*, int*>, int S::*>, "");
2525

26-
#if TEST_STD_VER > 2017
2726
template <class F, class... Is>
28-
constexpr bool has_indirect_result = requires { typename cuda::std::indirect_result_t<F, Is...>; };
29-
#else
30-
template <class F, class... Is>
31-
_CCCL_CONCEPT_FRAGMENT(has_indirect_result_, requires()(typename(cuda::std::indirect_result_t<F, Is...>)));
32-
33-
template <class F, class... Is>
34-
_CCCL_CONCEPT has_indirect_result = _CCCL_FRAGMENT(has_indirect_result_, F, Is...);
35-
#endif
27+
_CCCL_CONCEPT has_indirect_result =
28+
_CCCL_REQUIRES_EXPR((F, variadic Is))(typename(cuda::std::indirect_result_t<F, Is...>));
3629

3730
static_assert(!has_indirect_result<int (*)(int), int>, ""); // int isn't indirectly_readable
3831
static_assert(!has_indirect_result<int, int*>, ""); // int isn't invocable

libcudacxx/test/libcudacxx/std/iterators/iterator.requirements/indirectcallable/projected/projected.compile.pass.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,8 @@ static_assert(cuda::std::same_as<ContiguousIterator::value_type, S>, "");
5353
static_assert(cuda::std::same_as<decltype(*cuda::std::declval<ContiguousIterator>()), S&>, "");
5454
static_assert(cuda::std::same_as<cuda::std::iter_difference_t<ContiguousIterator>, cuda::std::ptrdiff_t>, "");
5555

56-
#if TEST_STD_VER > 2017
5756
template <class I, class F>
58-
constexpr bool projectable = requires { typename cuda::std::projected<I, F>; };
59-
#else
60-
template <class I, class F>
61-
_CCCL_CONCEPT_FRAGMENT(projectable_, requires()(typename(cuda::std::projected<I, F>)));
62-
63-
template <class I, class F>
64-
_CCCL_CONCEPT projectable = _CCCL_FRAGMENT(projectable_, I, F);
65-
#endif
57+
_CCCL_CONCEPT projectable = _CCCL_REQUIRES_EXPR((I, F))(typename(cuda::std::projected<I, F>));
6658

6759
static_assert(!projectable<int, void (*)(int)>, ""); // int isn't indirectly_readable
6860
static_assert(!projectable<S, void (*)(int)>, ""); // S isn't weakly_incrementable

libcudacxx/test/libcudacxx/std/iterators/iterator.requirements/iterator.assoc.types/incrementable.traits/incrementable_traits.compile.pass.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,14 @@
1515

1616
#include "test_macros.h"
1717

18-
#if TEST_STD_VER > 2017
1918
template <class T>
20-
concept check_has_difference_type = requires { typename cuda::std::incrementable_traits<T>::difference_type; };
19+
_CCCL_CONCEPT check_has_difference_type =
20+
_CCCL_REQUIRES_EXPR((T))(typename(typename cuda::std::incrementable_traits<T>::difference_type));
2121

2222
template <class T, class Expected>
23-
concept check_difference_type_matches =
24-
check_has_difference_type<T>
25-
&& cuda::std::same_as<typename cuda::std::incrementable_traits<T>::difference_type, Expected>;
26-
#else
27-
template <class T, class = void>
28-
_CCCL_INLINE_VAR constexpr bool check_has_difference_type = false;
29-
30-
template <class T>
31-
_CCCL_INLINE_VAR constexpr bool
32-
check_has_difference_type<T, cuda::std::void_t<typename cuda::std::incrementable_traits<T>::difference_type>> = true;
33-
34-
template <class T, class Expected>
35-
_CCCL_CONCEPT_FRAGMENT(
36-
check_difference_type_matches_,
37-
requires()(requires(check_has_difference_type<T>),
38-
requires(cuda::std::same_as<typename cuda::std::incrementable_traits<T>::difference_type, Expected>)));
39-
40-
template <class T, class Expected>
41-
_CCCL_CONCEPT check_difference_type_matches = _CCCL_FRAGMENT(check_difference_type_matches_, T, Expected);
42-
#endif
23+
_CCCL_CONCEPT check_difference_type_matches = _CCCL_REQUIRES_EXPR(
24+
(T, Expected))(requires(check_has_difference_type<T>),
25+
requires(cuda::std::same_as<typename cuda::std::incrementable_traits<T>::difference_type, Expected>));
4326

4427
template <class T, class Expected>
4528
__host__ __device__ constexpr bool check_incrementable_traits()

libcudacxx/test/libcudacxx/std/iterators/iterator.requirements/iterator.assoc.types/readable.traits/indirectly_readable_traits.compile.pass.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,14 @@
1313
#include <cuda/std/concepts>
1414
#include <cuda/std/iterator>
1515

16-
#if TEST_STD_VER > 2017
1716
template <class T>
18-
concept has_no_value_type = !requires { typename cuda::std::indirectly_readable_traits<T>::value_type; };
17+
_CCCL_CONCEPT has_no_value_type =
18+
!_CCCL_REQUIRES_EXPR((T))(typename(typename cuda::std::indirectly_readable_traits<T>::value_type));
1919

2020
template <class T, class Expected>
21-
concept value_type_matches =
22-
cuda::std::same_as<typename cuda::std::indirectly_readable_traits<T>::value_type, Expected>;
23-
24-
#else
25-
template <class T>
26-
_CCCL_CONCEPT_FRAGMENT(has_no_value_type_,
27-
requires()(typename(typename cuda::std::indirectly_readable_traits<T>::value_type)));
28-
29-
template <class T>
30-
_CCCL_CONCEPT has_no_value_type = !_CCCL_FRAGMENT(has_no_value_type_, T);
31-
32-
template <class T, class Expected>
33-
_CCCL_CONCEPT_FRAGMENT(
34-
value_type_matches_,
35-
requires()(typename(typename cuda::std::indirectly_readable_traits<T>::value_type),
36-
requires(cuda::std::same_as<typename cuda::std::indirectly_readable_traits<T>::value_type, Expected>)));
37-
38-
template <class T, class Expected>
39-
_CCCL_CONCEPT value_type_matches = _CCCL_FRAGMENT(value_type_matches_, T, Expected);
40-
#endif
21+
_CCCL_CONCEPT value_type_matches = _CCCL_REQUIRES_EXPR(
22+
(T, Expected))(typename(typename cuda::std::indirectly_readable_traits<T>::value_type),
23+
requires(cuda::std::same_as<typename cuda::std::indirectly_readable_traits<T>::value_type, Expected>));
4124

4225
template <class T>
4326
__host__ __device__ constexpr bool check_pointer()

libcudacxx/test/libcudacxx/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.readable/iter_common_reference_t.compile.pass.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,9 @@ struct T3
6565
static_assert(cuda::std::same_as<cuda::std::iter_common_reference_t<T3>, Common>, "");
6666

6767
// Make sure we're SFINAE-friendly
68-
#if TEST_STD_VER > 2017
6968
template <class T>
70-
constexpr bool has_common_reference = requires { typename cuda::std::iter_common_reference_t<T>; };
71-
#else
72-
template <class T>
73-
_CCCL_CONCEPT_FRAGMENT(has_common_reference_, requires()(typename(cuda::std::iter_common_reference_t<T>)));
69+
_CCCL_CONCEPT has_common_reference = _CCCL_REQUIRES_EXPR((T))(typename(cuda::std::iter_common_reference_t<T>));
7470

75-
template <class T>
76-
_CCCL_CONCEPT has_common_reference = _CCCL_FRAGMENT(has_common_reference_, T);
77-
#endif
7871
struct NotIndirectlyReadable
7972
{};
8073
static_assert(!has_common_reference<NotIndirectlyReadable>, "");

libcudacxx/test/libcudacxx/std/iterators/predef.iterators/reverse.iterators/sized_sentinel.compile.pass.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@
1414
#include "test_iterators.h"
1515
#include "test_macros.h"
1616

17-
#if TEST_STD_VER > 2017
1817
template <class T>
19-
concept HasMinus = requires(T t) { t - t; };
20-
#else
21-
template <class T>
22-
_CCCL_CONCEPT_FRAGMENT(HasMinus_, requires(T t)(t - t));
23-
24-
template <class T>
25-
_CCCL_CONCEPT HasMinus = _CCCL_FRAGMENT(HasMinus_, T);
26-
#endif
18+
_CCCL_CONCEPT HasMinus = _CCCL_REQUIRES_EXPR((T), T t)((t - t));
2719

2820
using sized_it = random_access_iterator<int*>;
2921
static_assert(cuda::std::sized_sentinel_for<sized_it, sized_it>);

libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.all/range.ref.view/range.ref.view.pass.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,31 +182,14 @@ struct Cpp20InputRange
182182
template <>
183183
inline constexpr bool cuda::std::ranges::enable_borrowed_range<Cpp20InputRange> = true;
184184

185-
#if TEST_STD_VER >= 2020
186-
template <class R>
187-
concept EmptyIsInvocable = requires(cuda::std::ranges::ref_view<R> view) { view.empty(); };
188-
189185
template <class R>
190-
concept SizeIsInvocable = requires(cuda::std::ranges::ref_view<R> view) { view.size(); };
186+
_CCCL_CONCEPT EmptyIsInvocable = _CCCL_REQUIRES_EXPR((R), cuda::std::ranges::ref_view<R> view)((view.empty()));
191187

192188
template <class R>
193-
concept DataIsInvocable = requires(cuda::std::ranges::ref_view<R> view) { view.data(); };
194-
#else // ^^^ C++20 ^^^ / vvv C++17 vvv
195-
template <class R>
196-
_CCCL_CONCEPT_FRAGMENT(EmptyIsInvocable_, requires(cuda::std::ranges::ref_view<R> view)((view.empty())));
197-
template <class R>
198-
_CCCL_CONCEPT EmptyIsInvocable = _CCCL_FRAGMENT(EmptyIsInvocable_, R);
189+
_CCCL_CONCEPT SizeIsInvocable = _CCCL_REQUIRES_EXPR((R), cuda::std::ranges::ref_view<R> view)((view.size()));
199190

200191
template <class R>
201-
_CCCL_CONCEPT_FRAGMENT(SizeIsInvocable_, requires(cuda::std::ranges::ref_view<R> view)((view.size())));
202-
template <class R>
203-
_CCCL_CONCEPT SizeIsInvocable = _CCCL_FRAGMENT(SizeIsInvocable_, R);
204-
205-
template <class R>
206-
_CCCL_CONCEPT_FRAGMENT(DataIsInvocable_, requires(cuda::std::ranges::ref_view<R> view)((view.data())));
207-
template <class R>
208-
_CCCL_CONCEPT DataIsInvocable = _CCCL_FRAGMENT(DataIsInvocable_, R);
209-
#endif // TEST_STD_VER <= 2017
192+
_CCCL_CONCEPT DataIsInvocable = _CCCL_REQUIRES_EXPR((R), cuda::std::ranges::ref_view<R> view)((view.data()));
210193

211194
// Testing ctad.
212195
static_assert(cuda::std::same_as<decltype(cuda::std::ranges::ref_view(cuda::std::declval<Range&>())),

libcudacxx/test/libcudacxx/std/utilities/expected/expected.expected/assign/emplace.intializer_list.pass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
#include "test_macros.h"
3232

3333
template <class T, class... Args>
34-
_CCCL_CONCEPT_FRAGMENT(CanEmplace_, requires(T t, Args&&... args)((t.emplace(cuda::std::forward<Args>(args)...))));
35-
template <class T, class... Args>
36-
constexpr bool CanEmplace = _CCCL_FRAGMENT(CanEmplace_, T, Args...);
34+
_CCCL_CONCEPT CanEmplace =
35+
_CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)((t.emplace(cuda::std::forward<Args>(args)...)));
3736

3837
static_assert(CanEmplace<cuda::std::expected<int, int>, int>, "");
3938

libcudacxx/test/libcudacxx/std/utilities/expected/expected.expected/assign/emplace.pass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
#include "test_macros.h"
3333

3434
template <class T, class... Args>
35-
_CCCL_CONCEPT_FRAGMENT(CanEmplace_, requires(T t, Args&&... args)((t.emplace(cuda::std::forward<Args>(args)...))));
36-
template <class T, class... Args>
37-
constexpr bool CanEmplace = _CCCL_FRAGMENT(CanEmplace_, T, Args...);
35+
_CCCL_CONCEPT CanEmplace =
36+
_CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)((t.emplace(cuda::std::forward<Args>(args)...)));
3837

3938
static_assert(CanEmplace<cuda::std::expected<int, int>, int>, "");
4039

0 commit comments

Comments
 (0)