| 1 |
// Copyright (C) 2019-2025 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-do compile { target c++20 } } |
| 19 |
|
| 20 |
#include <ranges> |
| 21 |
#include <span> |
| 22 |
#include <string_view> |
| 23 |
#include <experimental/string_view> |
| 24 |
#include <vector> |
| 25 |
#include <vector> |
| 26 |
#include <set> |
| 27 |
#include <unordered_set> |
| 28 |
#include <regex> |
| 29 |
#include <testsuite_iterators.h> |
| 30 |
|
| 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>); |
| 36 |
|
| 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>); |
| 47 |
|
| 48 |
// const test_random_access_range<T> is not a range: |
| 49 |
static_assert(!std::ranges::view<__gnu_test::test_random_access_range<int>>); |
| 50 |
|
| 51 |
template<typename T> |
| 52 |
struct test_view |
| 53 |
: __gnu_test::test_random_access_range<T>, std::ranges::view_base |
| 54 |
{ }; |
| 55 |
|
| 56 |
static_assert(std::ranges::view<test_view<int>>); |
| 57 |
|
| 58 |
template<> |
| 59 |
constexpr bool std::ranges::enable_view<test_view<long>> = false; |
| 60 |
|
| 61 |
static_assert(!std::ranges::view<test_view<long>>); |
| 62 |
|
| 63 |
void |
| 64 |
test01() |
| 65 |
{ |
| 66 |
// Verify LWG 3549 changes to ranges::enable_view. |
| 67 |
using std::ranges::view_interface; |
| 68 |
|
| 69 |
struct v1 |
| 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>); |
| 73 |
|
| 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>); |
| 77 |
|
| 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>); |
| 81 |
|
| 82 |
struct v4 { }; |
| 83 |
static_assert(!std::ranges::enable_view<view_interface<v4>>); |
| 84 |
} |