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