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