Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use _CCCL_REQUIRES_EXPR in test code #3954

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
#include "test_macros.h"

template <class T>
_CCCL_CONCEPT_FRAGMENT(brace_initializable_, requires()(T{}));

template <class T>
_CCCL_CONCEPT brace_initializable = _CCCL_FRAGMENT(brace_initializable_, T);
_CCCL_CONCEPT brace_initializable = _CCCL_REQUIRES_EXPR((T))((T{}));

__host__ __device__ void test()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ static_assert(cuda::std::same_as<cuda::std::indirect_result_t<long S::*, S*>, lo
static_assert(cuda::std::same_as<cuda::std::indirect_result_t<S && (S::*) (), S*>, S&&>, "");
static_assert(cuda::std::same_as<cuda::std::indirect_result_t<int S::* (S::*) (int) const, S*, int*>, int S::*>, "");

#if TEST_STD_VER > 2017
template <class F, class... Is>
constexpr bool has_indirect_result = requires { typename cuda::std::indirect_result_t<F, Is...>; };
#else
template <class F, class... Is>
_CCCL_CONCEPT_FRAGMENT(has_indirect_result_, requires()(typename(cuda::std::indirect_result_t<F, Is...>)));

template <class F, class... Is>
_CCCL_CONCEPT has_indirect_result = _CCCL_FRAGMENT(has_indirect_result_, F, Is...);
#endif
_CCCL_CONCEPT has_indirect_result =
_CCCL_REQUIRES_EXPR((F, variadic Is))(typename(cuda::std::indirect_result_t<F, Is...>));

static_assert(!has_indirect_result<int (*)(int), int>, ""); // int isn't indirectly_readable
static_assert(!has_indirect_result<int, int*>, ""); // int isn't invocable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,8 @@ static_assert(cuda::std::same_as<ContiguousIterator::value_type, S>, "");
static_assert(cuda::std::same_as<decltype(*cuda::std::declval<ContiguousIterator>()), S&>, "");
static_assert(cuda::std::same_as<cuda::std::iter_difference_t<ContiguousIterator>, cuda::std::ptrdiff_t>, "");

#if TEST_STD_VER > 2017
template <class I, class F>
constexpr bool projectable = requires { typename cuda::std::projected<I, F>; };
#else
template <class I, class F>
_CCCL_CONCEPT_FRAGMENT(projectable_, requires()(typename(cuda::std::projected<I, F>)));

template <class I, class F>
_CCCL_CONCEPT projectable = _CCCL_FRAGMENT(projectable_, I, F);
#endif
_CCCL_CONCEPT projectable = _CCCL_REQUIRES_EXPR((I, F))(typename(cuda::std::projected<I, F>));

static_assert(!projectable<int, void (*)(int)>, ""); // int isn't indirectly_readable
static_assert(!projectable<S, void (*)(int)>, ""); // S isn't weakly_incrementable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,14 @@

#include "test_macros.h"

#if TEST_STD_VER > 2017
template <class T>
concept check_has_difference_type = requires { typename cuda::std::incrementable_traits<T>::difference_type; };
_CCCL_CONCEPT check_has_difference_type =
_CCCL_REQUIRES_EXPR((T))(typename(typename cuda::std::incrementable_traits<T>::difference_type));

template <class T, class Expected>
concept check_difference_type_matches =
check_has_difference_type<T>
&& cuda::std::same_as<typename cuda::std::incrementable_traits<T>::difference_type, Expected>;
#else
template <class T, class = void>
_CCCL_INLINE_VAR constexpr bool check_has_difference_type = false;

template <class T>
_CCCL_INLINE_VAR constexpr bool
check_has_difference_type<T, cuda::std::void_t<typename cuda::std::incrementable_traits<T>::difference_type>> = true;

template <class T, class Expected>
_CCCL_CONCEPT_FRAGMENT(
check_difference_type_matches_,
requires()(requires(check_has_difference_type<T>),
requires(cuda::std::same_as<typename cuda::std::incrementable_traits<T>::difference_type, Expected>)));

template <class T, class Expected>
_CCCL_CONCEPT check_difference_type_matches = _CCCL_FRAGMENT(check_difference_type_matches_, T, Expected);
#endif
_CCCL_CONCEPT check_difference_type_matches = _CCCL_REQUIRES_EXPR(
(T, Expected))(requires(check_has_difference_type<T>),
requires(cuda::std::same_as<typename cuda::std::incrementable_traits<T>::difference_type, Expected>));

template <class T, class Expected>
__host__ __device__ constexpr bool check_incrementable_traits()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,14 @@
#include <cuda/std/concepts>
#include <cuda/std/iterator>

#if TEST_STD_VER > 2017
template <class T>
concept has_no_value_type = !requires { typename cuda::std::indirectly_readable_traits<T>::value_type; };
_CCCL_CONCEPT has_no_value_type =
!_CCCL_REQUIRES_EXPR((T))(typename(typename cuda::std::indirectly_readable_traits<T>::value_type));

template <class T, class Expected>
concept value_type_matches =
cuda::std::same_as<typename cuda::std::indirectly_readable_traits<T>::value_type, Expected>;

#else
template <class T>
_CCCL_CONCEPT_FRAGMENT(has_no_value_type_,
requires()(typename(typename cuda::std::indirectly_readable_traits<T>::value_type)));

template <class T>
_CCCL_CONCEPT has_no_value_type = !_CCCL_FRAGMENT(has_no_value_type_, T);

template <class T, class Expected>
_CCCL_CONCEPT_FRAGMENT(
value_type_matches_,
requires()(typename(typename cuda::std::indirectly_readable_traits<T>::value_type),
requires(cuda::std::same_as<typename cuda::std::indirectly_readable_traits<T>::value_type, Expected>)));

template <class T, class Expected>
_CCCL_CONCEPT value_type_matches = _CCCL_FRAGMENT(value_type_matches_, T, Expected);
#endif
_CCCL_CONCEPT value_type_matches = _CCCL_REQUIRES_EXPR(
(T, Expected))(typename(typename cuda::std::indirectly_readable_traits<T>::value_type),
requires(cuda::std::same_as<typename cuda::std::indirectly_readable_traits<T>::value_type, Expected>));

template <class T>
__host__ __device__ constexpr bool check_pointer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,9 @@ struct T3
static_assert(cuda::std::same_as<cuda::std::iter_common_reference_t<T3>, Common>, "");

// Make sure we're SFINAE-friendly
#if TEST_STD_VER > 2017
template <class T>
constexpr bool has_common_reference = requires { typename cuda::std::iter_common_reference_t<T>; };
#else
template <class T>
_CCCL_CONCEPT_FRAGMENT(has_common_reference_, requires()(typename(cuda::std::iter_common_reference_t<T>)));
_CCCL_CONCEPT has_common_reference = _CCCL_REQUIRES_EXPR((T))(typename(cuda::std::iter_common_reference_t<T>));

template <class T>
_CCCL_CONCEPT has_common_reference = _CCCL_FRAGMENT(has_common_reference_, T);
#endif
struct NotIndirectlyReadable
{};
static_assert(!has_common_reference<NotIndirectlyReadable>, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@
#include "test_iterators.h"
#include "test_macros.h"

#if TEST_STD_VER > 2017
template <class T>
concept HasMinus = requires(T t) { t - t; };
#else
template <class T>
_CCCL_CONCEPT_FRAGMENT(HasMinus_, requires(T t)(t - t));

template <class T>
_CCCL_CONCEPT HasMinus = _CCCL_FRAGMENT(HasMinus_, T);
#endif
_CCCL_CONCEPT HasMinus = _CCCL_REQUIRES_EXPR((T), T t)((t - t));

using sized_it = random_access_iterator<int*>;
static_assert(cuda::std::sized_sentinel_for<sized_it, sized_it>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,14 @@ struct Cpp20InputRange
template <>
inline constexpr bool cuda::std::ranges::enable_borrowed_range<Cpp20InputRange> = true;

#if TEST_STD_VER >= 2020
template <class R>
concept EmptyIsInvocable = requires(cuda::std::ranges::ref_view<R> view) { view.empty(); };

template <class R>
concept SizeIsInvocable = requires(cuda::std::ranges::ref_view<R> view) { view.size(); };
_CCCL_CONCEPT EmptyIsInvocable = _CCCL_REQUIRES_EXPR((R), cuda::std::ranges::ref_view<R> view)((view.empty()));

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

template <class R>
_CCCL_CONCEPT_FRAGMENT(SizeIsInvocable_, requires(cuda::std::ranges::ref_view<R> view)((view.size())));
template <class R>
_CCCL_CONCEPT SizeIsInvocable = _CCCL_FRAGMENT(SizeIsInvocable_, R);

template <class R>
_CCCL_CONCEPT_FRAGMENT(DataIsInvocable_, requires(cuda::std::ranges::ref_view<R> view)((view.data())));
template <class R>
_CCCL_CONCEPT DataIsInvocable = _CCCL_FRAGMENT(DataIsInvocable_, R);
#endif // TEST_STD_VER <= 2017
_CCCL_CONCEPT DataIsInvocable = _CCCL_REQUIRES_EXPR((R), cuda::std::ranges::ref_view<R> view)((view.data()));

// Testing ctad.
static_assert(cuda::std::same_as<decltype(cuda::std::ranges::ref_view(cuda::std::declval<Range&>())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
#include "test_macros.h"

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
#include "test_macros.h"

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));
static_assert(ImplicitlyConstructible<int, int>, "");

static_assert(!ImplicitlyConstructible<cuda::std::expected<int, int>, cuda::std::in_place_t>, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));
static_assert(ImplicitlyConstructible<int, int>, "");

#if defined(_LIBCUDACXX_HAS_VECTOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));
static_assert(ImplicitlyConstructible<int, int>, "");

static_assert(!ImplicitlyConstructible<cuda::std::expected<int, int>, cuda::std::unexpect_t>, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));
static_assert(ImplicitlyConstructible<int, int>, "");

#if defined(_LIBCUDACXX_HAS_VECTOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@

// Test Constraints:
template <class T, class E>
_CCCL_CONCEPT_FRAGMENT(HasMemberSwap_, requires(cuda::std::expected<T, E> x, cuda::std::expected<T, E> y)((x.swap(y))));
template <class T, class E>
_CCCL_CONCEPT HasMemberSwap = _CCCL_FRAGMENT(HasMemberSwap_, T, E);
_CCCL_CONCEPT HasMemberSwap =
_CCCL_REQUIRES_EXPR((T, E), cuda::std::expected<T, E> x, cuda::std::expected<T, E> y)((x.swap(y)));

static_assert(HasMemberSwap<int, int>, "");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));

static_assert(ImplicitlyConstructible<int, int>, "");
static_assert(!ImplicitlyConstructible<cuda::std::unexpected<int>, cuda::std::in_place_t, int>, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));

static_assert(ImplicitlyConstructible<int, int>, "");
static_assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));
static_assert(ImplicitlyConstructible<int, int>, "");

static_assert(!ImplicitlyConstructible<cuda::std::expected<void, int>, cuda::std::unexpect_t>, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ template <class T>
__host__ __device__ void conversion_test(T);

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(ImplicitlyConstructible_,
requires(Args&&... args)((conversion_test<T>({cuda::std::forward<Args>(args)...}))));

template <class T, class... Args>
constexpr bool ImplicitlyConstructible = _CCCL_FRAGMENT(ImplicitlyConstructible_, T, Args...);
_CCCL_CONCEPT ImplicitlyConstructible = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(conversion_test<T>({cuda::std::forward<Args>(args)...})));
static_assert(ImplicitlyConstructible<int, int>, "");

#if defined(_LIBCUDACXX_HAS_VECTOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@

// Test Constraints:
template <class E>
_CCCL_CONCEPT_FRAGMENT(HasMemberSwap_,
requires(cuda::std::expected<void, E> x, cuda::std::expected<void, E> y)((x.swap(y))));
template <class E>
_CCCL_CONCEPT HasMemberSwap = _CCCL_FRAGMENT(HasMemberSwap_, E);
_CCCL_CONCEPT HasMemberSwap =
_CCCL_REQUIRES_EXPR((E), cuda::std::expected<void, E> x, cuda::std::expected<void, E> y)((x.swap(y)));

static_assert(HasMemberSwap<int>, "");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
#include "test_macros.h"

template <class T, class... Args>
_CCCL_CONCEPT_FRAGMENT(
HasMakeUniqueForOverwrite_,
requires(Args&&... args)((cuda::std::make_unique_for_overwrite<T>(cuda::std::forward<Args>(args)...))));
template <class T, class... Args>
constexpr bool HasMakeUniqueForOverwrite = _CCCL_FRAGMENT(HasMakeUniqueForOverwrite_, T, Args...);
_CCCL_CONCEPT HasMakeUniqueForOverwrite = _CCCL_REQUIRES_EXPR((T, variadic Args), T t, Args&&... args)(
(cuda::std::make_unique_for_overwrite<T>(cuda::std::forward<Args>(args)...)));

struct Foo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,9 @@ struct NonMovable
NonMovable(NonMovable&&) = delete;
};

#if TEST_STD_VER > 2017

template <class Opt, class F>
concept has_or_else = requires(Opt&& opt, F&& f) {
{ cuda::std::forward<Opt>(opt).or_else(cuda::std::forward<F>(f)) };
};

#else

template <class Opt, class F>
_CCCL_CONCEPT_FRAGMENT(HasOrElse,
requires(Opt&& opt, F&& f)(cuda::std::forward<Opt>(opt).or_else(cuda::std::forward<F>(f))));

template <class Opt, class F>
_CCCL_CONCEPT has_or_else = _CCCL_FRAGMENT(HasOrElse, Opt, F);

#endif
_CCCL_CONCEPT has_or_else =
_CCCL_REQUIRES_EXPR((Opt, F), Opt&& opt, F&& f)((cuda::std::forward<Opt>(opt).or_else(cuda::std::forward<F>(f))));

template <class T>
__host__ __device__ cuda::std::optional<T> return_optional();
Expand Down
Loading