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 // UNSUPPORTED: c++03, c++11, c++14, c++17 10 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 11 12 // <ranges> 13 14 // template<class T> 15 // concept view = ...; 16 17 #include <ranges> 18 19 #include "test_macros.h" 20 21 // The type would be a view, but it's not moveable. 22 struct NotMoveable : std::ranges::view_base { 23 NotMoveable() = default; 24 NotMoveable(NotMoveable&&) = delete; 25 NotMoveable& operator=(NotMoveable&&) = delete; 26 friend int* begin(NotMoveable&); 27 friend int* begin(NotMoveable const&); 28 friend int* end(NotMoveable&); 29 friend int* end(NotMoveable const&); 30 }; 31 static_assert(std::ranges::range<NotMoveable>); 32 static_assert(!std::movable<NotMoveable>); 33 static_assert(std::default_initializable<NotMoveable>); 34 static_assert(std::ranges::enable_view<NotMoveable>); 35 static_assert(!std::ranges::view<NotMoveable>); 36 37 // The type would be a view, but it's not default initializable 38 struct NotDefaultInit : std::ranges::view_base { 39 NotDefaultInit() = delete; 40 friend int* begin(NotDefaultInit&); 41 friend int* begin(NotDefaultInit const&); 42 friend int* end(NotDefaultInit&); 43 friend int* end(NotDefaultInit const&); 44 }; 45 static_assert(std::ranges::range<NotDefaultInit>); 46 static_assert(std::movable<NotDefaultInit>); 47 static_assert(!std::default_initializable<NotDefaultInit>); 48 static_assert(std::ranges::enable_view<NotDefaultInit>); 49 static_assert(std::ranges::view<NotDefaultInit>); 50 51 // The type would be a view, but it doesn't enable it with enable_view 52 struct NotExplicitlyEnabled { 53 NotExplicitlyEnabled() = default; 54 NotExplicitlyEnabled(NotExplicitlyEnabled&&) = default; 55 NotExplicitlyEnabled& operator=(NotExplicitlyEnabled&&) = default; 56 friend int* begin(NotExplicitlyEnabled&); 57 friend int* begin(NotExplicitlyEnabled const&); 58 friend int* end(NotExplicitlyEnabled&); 59 friend int* end(NotExplicitlyEnabled const&); 60 }; 61 static_assert(std::ranges::range<NotExplicitlyEnabled>); 62 static_assert(std::movable<NotExplicitlyEnabled>); 63 static_assert(std::default_initializable<NotExplicitlyEnabled>); 64 static_assert(!std::ranges::enable_view<NotExplicitlyEnabled>); 65 static_assert(!std::ranges::view<NotExplicitlyEnabled>); 66 67 // The type has everything else, but it's not a range 68 struct NotARange : std::ranges::view_base { 69 NotARange() = default; 70 NotARange(NotARange&&) = default; 71 NotARange& operator=(NotARange&&) = default; 72 }; 73 static_assert(!std::ranges::range<NotARange>); 74 static_assert(std::movable<NotARange>); 75 static_assert(std::default_initializable<NotARange>); 76 static_assert(std::ranges::enable_view<NotARange>); 77 static_assert(!std::ranges::view<NotARange>); 78 79 // The type satisfies all requirements 80 struct View : std::ranges::view_base { 81 View() = default; 82 View(View&&) = default; 83 View& operator=(View&&) = default; 84 friend int* begin(View&); 85 friend int* begin(View const&); 86 friend int* end(View&); 87 friend int* end(View const&); 88 }; 89 static_assert(std::ranges::range<View>); 90 static_assert(std::movable<View>); 91 static_assert(std::default_initializable<View>); 92 static_assert(std::ranges::enable_view<View>); 93 static_assert(std::ranges::view<View>); 94