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