1 // Copyright (C) 2019 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
&&); // not defined
33 friend constexpr const int* rend(const R1
&&); // not defined
36 // N.B. this is a lie, rend on an R1 rvalue will return a dangling pointer.
37 template<> constexpr bool std::ranges::enable_safe_range
<R1
> = true;
43 static_assert( std::ranges::rend(r
) == &r
.i
+ 1 );
44 static_assert( std::ranges::rend(std::move(r
)) == &r
.i
+ 1 );
52 constexpr const int* begin() const { return a
; }
53 constexpr const int* end() const { return a
+ 2; }
55 friend constexpr const long* begin(const R2
&& r
) { return r
.l
; }
56 friend constexpr const long* end(const R2
&& r
) { return r
.l
+ 2; }
59 // N.B. this is a lie, begin/end on an R2 rvalue will return a dangling pointer.
60 template<> constexpr bool std::ranges::enable_safe_range
<R2
> = true;
66 static_assert( std::ranges::rend(r
)
67 == std::make_reverse_iterator(std::ranges::begin(r
)) );
68 static_assert( std::ranges::rend(std::move(r
))
69 == std::make_reverse_iterator(std::ranges::begin(std::move(r
))) );
76 int* rbegin() noexcept
{ return &i
+ 1; }
77 long* rend() noexcept
{ return nullptr; } // not a sentinel for rbegin()
79 friend long* rbegin(R3
&) noexcept
{ return nullptr; }
80 friend int* rend(R3
& r
) { return &r
.i
; }
87 auto i1
= std::ranges::rbegin(r
);
89 static_assert( std::sentinel_for
<decltype(i2
), decltype(i1
)> );
90 // VERIFY( std::ranges::rend(r) == r.i );
91 // static_assert( !noexcept(std::ranges::rend(r)) );
97 using __gnu_test::test_range
;
98 using __gnu_test::bidirectional_iterator_wrapper
;
101 test_range
<int, bidirectional_iterator_wrapper
> r(a
);
102 VERIFY( std::ranges::rend(r
) == std::make_reverse_iterator(std::ranges::begin(r
)) );