1 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17 
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
20 
21 #include <ranges>
22 #include <span>
23 #include <string_view>
24 #include <experimental/string_view>
25 #include <vector>
26 #include <vector>
27 #include <set>
28 #include <unordered_set>
29 #include <regex>
30 #include <testsuite_iterators.h>
31 
32 static_assert(std::ranges::view<std::span<int>>);
33 static_assert(std::ranges::view<std::span<int, 0>>);
34 static_assert(!std::ranges::view<std::span<int, 1>>);
35 static_assert(std::ranges::view<std::string_view>);
36 static_assert(std::ranges::view<std::experimental::string_view>);
37 
38 static_assert(!std::ranges::view<std::vector<int>>);
39 static_assert(!std::ranges::view<const std::vector<int>>);
40 static_assert(!std::ranges::view<std::initializer_list<int>>);
41 static_assert(!std::ranges::view<const std::initializer_list<int>>);
42 static_assert(!std::ranges::view<std::set<int>>);
43 static_assert(!std::ranges::view<const std::set<int>>);
44 static_assert(!std::ranges::view<std::multiset<int>>);
45 static_assert(!std::ranges::view<std::unordered_set<int>>);
46 static_assert(!std::ranges::view<std::unordered_multiset<int>>);
47 static_assert(!std::ranges::view<std::cmatch>);
48 
49 // const test_random_access_range<T> is not a range:
50 static_assert(!std::ranges::view<__gnu_test::test_random_access_range<int>>);
51 
52 template<typename T>
53 struct test_view
54 : __gnu_test::test_random_access_range<T>, std::ranges::view_base
55 {
56   // views must be default-initializable:
test_viewtest_view57   test_view() : __gnu_test::test_random_access_range<T>(nullptr, nullptr) { }
58 };
59 
60 static_assert(std::ranges::view<test_view<int>>);
61 
62 template<>
63 constexpr bool std::ranges::enable_view<test_view<long>> = false;
64 
65 static_assert(!std::ranges::view<test_view<long>>);
66