]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/view.cc
1 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do compile { target c++20 } }
22 #include <string_view>
23 #include <experimental/string_view>
27 #include <unordered_set>
29 #include <testsuite_iterators.h>
31 static_assert(std::ranges::view
<std::span
<int>>);
32 static_assert(std::ranges::view
<std::span
<int, 0>>);
33 static_assert(std::ranges::view
<std::span
<int, 1>>); // Changed with P2325R3
34 static_assert(std::ranges::view
<std::string_view
>);
35 static_assert(std::ranges::view
<std::experimental::string_view
>);
37 static_assert(!std::ranges::view
<std::vector
<int>>);
38 static_assert(!std::ranges::view
<const std::vector
<int>>);
39 static_assert(!std::ranges::view
<std::initializer_list
<int>>);
40 static_assert(!std::ranges::view
<const std::initializer_list
<int>>);
41 static_assert(!std::ranges::view
<std::set
<int>>);
42 static_assert(!std::ranges::view
<const std::set
<int>>);
43 static_assert(!std::ranges::view
<std::multiset
<int>>);
44 static_assert(!std::ranges::view
<std::unordered_set
<int>>);
45 static_assert(!std::ranges::view
<std::unordered_multiset
<int>>);
46 static_assert(!std::ranges::view
<std::cmatch
>);
48 // const test_random_access_range<T> is not a range:
49 static_assert(!std::ranges::view
<__gnu_test::test_random_access_range
<int>>);
53 : __gnu_test::test_random_access_range
<T
>, std::ranges::view_base
56 static_assert(std::ranges::view
<test_view
<int>>);
59 constexpr bool std::ranges::enable_view
<test_view
<long>> = false;
61 static_assert(!std::ranges::view
<test_view
<long>>);
66 // Verify LWG 3549 changes to ranges::enable_view.
67 using std::ranges::view_interface
;
70 : __gnu_test::test_random_access_range
<int>, view_interface
<v1
> { };
71 static_assert(!std::derived_from
<v1
, std::ranges::view_base
>);
72 static_assert(std::ranges::enable_view
<v1
>);
74 struct v2
: v1
, view_interface
<v2
> { };
75 static_assert(!std::derived_from
<v2
, std::ranges::view_base
>);
76 static_assert(!std::ranges::enable_view
<v2
>);
78 struct v3
: __gnu_test::test_random_access_range
<int> { };
79 static_assert(!std::derived_from
<v3
, std::ranges::view_base
>);
80 static_assert(!std::ranges::enable_view
<v3
>);
83 static_assert(!std::ranges::enable_view
<view_interface
<v4
>>);