1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LIBCXX_TEST_SUPPORT_TEST_RANGE_H
10 #define LIBCXX_TEST_SUPPORT_TEST_RANGE_H
16 #include <type_traits>
18 #include "test_iterators.h"
21 # error "test/support/test_range.h" can only be included in builds supporting ranges
25 bool operator==(std::input_or_output_iterator
auto const&) const;
28 template <template <class...> class I
, class T
= int>
29 requires
std::input_or_output_iterator
<I
<T
*> >
32 I
<T
const*> begin() const;
37 template <template <class...> class I
, class T
= int>
38 requires
std::input_or_output_iterator
<I
<T
*> >
39 struct test_non_const_range
{
44 template <template <class...> class I
, class T
= int>
45 requires
std::input_or_output_iterator
<I
<T
*> >
46 struct test_common_range
{
48 I
<T
const*> begin() const;
50 I
<T
const*> end() const;
53 template <template <class...> class I
, class T
= int>
54 requires
std::input_or_output_iterator
<I
<T
*> >
55 struct test_non_const_common_range
{
60 template <template <class...> class I
, class T
= int>
61 requires
std::input_or_output_iterator
<I
<T
*> >
62 struct test_view
: std::ranges::view_base
{
64 I
<T
const*> begin() const;
69 template <class T
= int>
70 struct BorrowedRange
{
73 BorrowedRange(BorrowedRange
&&) = delete;
76 inline constexpr bool std::ranges::enable_borrowed_range
<BorrowedRange
<T
>> = true;
77 static_assert(!std::ranges::view
<BorrowedRange
<>>);
78 static_assert(std::ranges::borrowed_range
<BorrowedRange
<>>);
80 using BorrowedView
= std::ranges::empty_view
<int>;
81 static_assert(std::ranges::view
<BorrowedView
>);
82 static_assert(std::ranges::borrowed_range
<BorrowedView
>);
84 using NonBorrowedView
= std::ranges::single_view
<int>;
85 static_assert(std::ranges::view
<NonBorrowedView
>);
86 static_assert(!std::ranges::borrowed_range
<NonBorrowedView
>);
88 template <class Range
>
90 std::ranges::view
<Range
> && std::ranges::range
<const Range
> &&
91 std::same_as
<std::ranges::iterator_t
<Range
>, std::ranges::iterator_t
<const Range
>> &&
92 std::same_as
<std::ranges::sentinel_t
<Range
>, std::ranges::sentinel_t
<const Range
>>;
94 template <class View
, class T
>
95 concept CanBePiped
= requires(View
&& view
, T
&& t
) {
96 { std::forward
<View
>(view
) | std::forward
<T
>(t
) };
99 // See [concept.equalitycomparable]
100 template <class T
, class U
>
101 concept weakly_equality_comparable_with
=
102 requires(const std::remove_reference_t
<T
>& t
, const std::remove_reference_t
<U
>& u
) {
103 { t
== u
} -> std::same_as
<bool>;
104 { t
!= u
} -> std::same_as
<bool>;
105 { u
== t
} -> std::same_as
<bool>;
106 { u
!= t
} -> std::same_as
<bool>;
109 #endif // LIBCXX_TEST_SUPPORT_TEST_RANGE_H