]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/safe_range_types.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / ranges / safe_range_types.cc
1 // Copyright (C) 2019-2023 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>
24 #include <experimental/string_view>
25
26 template<typename T>
27 constexpr bool
28 rvalue_is_borrowed_range()
29 {
30 using std::ranges::borrowed_range;
31
32 // An lvalue range always models borrowed_range
33 static_assert( borrowed_range<T&> );
34 static_assert( borrowed_range<const T&> );
35
36 // Result should not depend on addition of const or rvalue-reference.
37 static_assert( borrowed_range<T&&> == borrowed_range<T> );
38 static_assert( borrowed_range<const T> == borrowed_range<T> );
39 static_assert( borrowed_range<const T&&> == borrowed_range<T> );
40
41 return std::ranges::borrowed_range<T>;
42 }
43
44 static_assert( rvalue_is_borrowed_range<std::ranges::subrange<int*, int*>>() );
45 static_assert( rvalue_is_borrowed_range<std::ranges::empty_view<int>>() );
46 static_assert( rvalue_is_borrowed_range<std::ranges::iota_view<int>>() );
47 static_assert( rvalue_is_borrowed_range<std::ranges::iota_view<int, int>>() );
48
49 static_assert( rvalue_is_borrowed_range<std::span<int>>() );
50 static_assert( rvalue_is_borrowed_range<std::span<int, 99>>() );
51
52 static_assert( ! rvalue_is_borrowed_range<std::string>() );
53 static_assert( ! rvalue_is_borrowed_range<std::wstring>() );
54
55 static_assert( rvalue_is_borrowed_range<std::string_view>() );
56 static_assert( rvalue_is_borrowed_range<std::wstring_view>() );
57
58 static_assert( rvalue_is_borrowed_range<std::experimental::string_view>() );
59 static_assert( rvalue_is_borrowed_range<std::experimental::wstring_view>() );