]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/access/crend.cc
1 // Copyright (C) 2019-2021 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 run { target c++2a } }
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
30 constexpr const int* rbegin() const { return &i
; }
31 constexpr const int* rend() const { return &i
+ 1; }
32 friend constexpr const int* rbegin(const R1
&& r
) { return &r
.j
; }
33 friend constexpr const int* rend(const R1
&& r
) { return &r
.j
+ 1; }
36 // N.B. this is a lie, rend on an R1 rvalue will return a dangling pointer.
37 template<> constexpr bool std::ranges::enable_borrowed_range
<R1
> = true;
44 VERIFY( std::ranges::crend(r
) == std::ranges::rend(c
) );
45 VERIFY( std::ranges::crend(c
) == std::ranges::rend(c
) );
46 VERIFY( std::ranges::crend(std::move(r
)) == std::ranges::rend(c
) );
47 VERIFY( std::ranges::crend(std::move(c
)) == std::ranges::rend(c
) );
55 const int* begin() const { return a
; }
56 const int* end() const { return a
+ 2; }
58 friend const long* begin(const R2
&& r
) { return r
.l
; }
59 friend const long* end(const R2
&& r
) { return r
.l
+ 2; }
62 // N.B. this is a lie, rend on an R2 rvalue will return a dangling pointer.
63 template<> constexpr bool std::ranges::enable_borrowed_range
<R2
> = true;
70 VERIFY( std::ranges::crend(r
) == std::ranges::rend(c
) );
71 VERIFY( std::ranges::crend(c
) == std::ranges::rend(c
) );
72 VERIFY( std::ranges::crend(std::move(r
)) == std::ranges::rend(std::move(c
)) );
73 VERIFY( std::ranges::crend(std::move(c
)) == std::ranges::rend(std::move(c
)) );
80 const int* rbegin() const noexcept
{ return &i
+ 1; }
81 const long* rend() const noexcept
{ return nullptr; } // not a sentinel for rbegin()
83 friend const long* rbegin(const R3
&) noexcept
{ return nullptr; }
84 friend const int* rend(const R3
& r
) { return &r
.i
; }
87 // N.B. this is a lie, rend on an R3 rvalue will return a dangling pointer.
88 template<> constexpr bool std::ranges::enable_borrowed_range
<R3
> = true;
95 VERIFY( std::ranges::crend(r
) == std::ranges::rend(c
) );
96 static_assert( !noexcept(std::ranges::crend(r
)) );
97 VERIFY( std::ranges::crend(c
) == std::ranges::rend(c
) );
98 static_assert( !noexcept(std::ranges::crend(c
)) );
106 VERIFY( std::ranges::crend(a
) == std::ranges::rend(c
) );
107 VERIFY( std::ranges::crend(c
) == std::ranges::rend(c
) );