• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <iterator>
13 #include <ranges>
14 
15 #include "test_iterators.h"
16 
17 #if TEST_STD_VER < 17
18 #error "test/support/test_range.h" can only be included in builds supporting ranges
19 #endif
20 
21 struct sentinel {
22   bool operator==(std::input_or_output_iterator auto const&) const;
23 };
24 
25 template <template <class...> class I>
26 requires std::input_or_output_iterator<I<int*> >
27 struct test_range {
28   I<int*> begin();
29   I<int const*> begin() const;
30   sentinel end();
31   sentinel end() const;
32 };
33 
34 template <template <class...> class I>
35 requires std::input_or_output_iterator<I<int*> >
36 struct test_non_const_range {
37   I<int*> begin();
38   sentinel end();
39 };
40 
41 template <template <class...> class I>
42 requires std::input_or_output_iterator<I<int*> >
43 struct test_common_range {
44   I<int*> begin();
45   I<int const*> begin() const;
46   I<int*> end();
47   I<int const*> end() const;
48 };
49 
50 template <template <class...> class I>
51 requires std::input_or_output_iterator<I<int*> >
52 struct test_non_const_common_range {
53   I<int*> begin();
54   I<int*> end();
55 };
56 
57 template <template <class...> class I>
58 requires std::input_or_output_iterator<I<int*> >
59 struct test_view : std::ranges::view_base {
60   I<int*> begin();
61   I<int const*> begin() const;
62   sentinel end();
63   sentinel end() const;
64 };
65 
66 struct BorrowedRange {
67   int *begin() const;
68   int *end() const;
69   BorrowedRange(BorrowedRange&&) = delete;
70 };
71 template<> inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;
72 static_assert(!std::ranges::view<BorrowedRange>);
73 static_assert(std::ranges::borrowed_range<BorrowedRange>);
74 
75 using BorrowedView = std::ranges::empty_view<int>;
76 static_assert(std::ranges::view<BorrowedView>);
77 static_assert(std::ranges::borrowed_range<BorrowedView>);
78 
79 using NonBorrowedView = std::ranges::single_view<int>;
80 static_assert(std::ranges::view<NonBorrowedView>);
81 static_assert(!std::ranges::borrowed_range<NonBorrowedView>);
82 
83 #endif // LIBCXX_TEST_SUPPORT_TEST_RANGE_H
84