]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2019-2022 Free Software Foundation, Inc. |
b5b2e387 JW |
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 | |
15411a64 | 28 | rvalue_is_borrowed_range() |
b5b2e387 | 29 | { |
15411a64 | 30 | using std::ranges::borrowed_range; |
b5b2e387 | 31 | |
15411a64 JW |
32 | // An lvalue range always models borrowed_range |
33 | static_assert( borrowed_range<T&> ); | |
34 | static_assert( borrowed_range<const T&> ); | |
b5b2e387 JW |
35 | |
36 | // Result should not depend on addition of const or rvalue-reference. | |
15411a64 JW |
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> ); | |
b5b2e387 | 40 | |
15411a64 | 41 | return std::ranges::borrowed_range<T>; |
b5b2e387 JW |
42 | } |
43 | ||
15411a64 JW |
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>>() ); | |
b5b2e387 | 48 | |
15411a64 JW |
49 | static_assert( rvalue_is_borrowed_range<std::span<int>>() ); |
50 | static_assert( rvalue_is_borrowed_range<std::span<int, 99>>() ); | |
b5b2e387 | 51 | |
15411a64 JW |
52 | static_assert( ! rvalue_is_borrowed_range<std::string>() ); |
53 | static_assert( ! rvalue_is_borrowed_range<std::wstring>() ); | |
b5b2e387 | 54 | |
15411a64 JW |
55 | static_assert( rvalue_is_borrowed_range<std::string_view>() ); |
56 | static_assert( rvalue_is_borrowed_range<std::wstring_view>() ); | |
b5b2e387 | 57 | |
15411a64 JW |
58 | static_assert( rvalue_is_borrowed_range<std::experimental::string_view>() ); |
59 | static_assert( rvalue_is_borrowed_range<std::experimental::wstring_view>() ); |