1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LIBCXX_TEST_SUPPORT_TEST_RANGE_H
10 #define LIBCXX_TEST_SUPPORT_TEST_RANGE_H
11
12 #include <concepts>
13 #include <iterator>
14 #include <ranges>
15
16 #include "test_iterators.h"
17
18 #if TEST_STD_VER < 17
19 # error "test/support/test_range.h" can only be included in builds supporting ranges
20 #endif
21
22 struct sentinel {
23 bool operator==(std::input_or_output_iterator auto const&) const;
24 };
25
26 template <template <class...> class I, class T = int>
27 requires std::input_or_output_iterator<I<T*> >
28 struct test_range {
29 I<T*> begin();
30 I<T const*> begin() const;
31 sentinel end();
32 sentinel end() const;
33 };
34
35 template <template <class...> class I, class T = int>
36 requires std::input_or_output_iterator<I<T*> >
37 struct test_non_const_range {
38 I<T*> begin();
39 sentinel end();
40 };
41
42 template <template <class...> class I, class T = int>
43 requires std::input_or_output_iterator<I<T*> >
44 struct test_common_range {
45 I<T*> begin();
46 I<T const*> begin() const;
47 I<T*> end();
48 I<T const*> end() const;
49 };
50
51 template <template <class...> class I, class T = int>
52 requires std::input_or_output_iterator<I<T*> >
53 struct test_non_const_common_range {
54 I<T*> begin();
55 I<T*> end();
56 };
57
58 template <template <class...> class I, class T = int>
59 requires std::input_or_output_iterator<I<T*> >
60 struct test_view : std::ranges::view_base {
61 I<T*> begin();
62 I<T const*> begin() const;
63 sentinel end();
64 sentinel end() const;
65 };
66
67 template <class T = int>
68 struct BorrowedRange {
69 T* begin() const;
70 T* end() const;
71 BorrowedRange(BorrowedRange&&) = delete;
72 };
73 template <class T>
74 inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange<T>> = true;
75 static_assert(!std::ranges::view<BorrowedRange<>>);
76 static_assert(std::ranges::borrowed_range<BorrowedRange<>>);
77
78 using BorrowedView = std::ranges::empty_view<int>;
79 static_assert(std::ranges::view<BorrowedView>);
80 static_assert(std::ranges::borrowed_range<BorrowedView>);
81
82 using NonBorrowedView = std::ranges::single_view<int>;
83 static_assert(std::ranges::view<NonBorrowedView>);
84 static_assert(!std::ranges::borrowed_range<NonBorrowedView>);
85
86 template <class Range>
87 concept simple_view =
88 std::ranges::view<Range> && std::ranges::range<const Range> &&
89 std::same_as<std::ranges::iterator_t<Range>, std::ranges::iterator_t<const Range>> &&
90 std::same_as<std::ranges::sentinel_t<Range>, std::ranges::sentinel_t<const Range>>;
91
92 template <class View, class T>
requires(View && view,T && t)93 concept CanBePiped = requires(View&& view, T&& t) {
94 { std::forward<View>(view) | std::forward<T>(t) };
95 };
96
97 #endif // LIBCXX_TEST_SUPPORT_TEST_RANGE_H
98