]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/safe_range_types.cc
3f0b52404a10c13cf9e95e3ee84c12bc8d127dc4
1 // Copyright (C) 2019-2020 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-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
24 #include <experimental/string_view>
28 rvalue_is_safe_range()
30 using std::ranges::safe_range
;
32 // An lvalue range always models safe_range
33 static_assert( safe_range
<T
&> );
34 static_assert( safe_range
<const T
&> );
36 // Result should not depend on addition of const or rvalue-reference.
37 static_assert( safe_range
<T
&&> == safe_range
<T
> );
38 static_assert( safe_range
<const T
> == safe_range
<T
> );
39 static_assert( safe_range
<const T
&&> == safe_range
<T
> );
41 return std::ranges::safe_range
<T
>;
44 static_assert( rvalue_is_safe_range
<std::ranges::subrange
<int*, int*>>() );
45 static_assert( rvalue_is_safe_range
<std::ranges::empty_view
<int>>() );
46 static_assert( rvalue_is_safe_range
<std::ranges::iota_view
<int>>() );
47 static_assert( rvalue_is_safe_range
<std::ranges::iota_view
<int, int>>() );
49 static_assert( rvalue_is_safe_range
<std::span
<int>>() );
50 static_assert( rvalue_is_safe_range
<std::span
<int, 99>>() );
52 static_assert( ! rvalue_is_safe_range
<std::string
>() );
53 static_assert( ! rvalue_is_safe_range
<std::wstring
>() );
55 static_assert( rvalue_is_safe_range
<std::string_view
>() );
56 static_assert( rvalue_is_safe_range
<std::wstring_view
>() );
58 static_assert( rvalue_is_safe_range
<std::experimental::string_view
>() );
59 static_assert( rvalue_is_safe_range
<std::experimental::wstring_view
>() );