]>
Commit | Line | Data |
---|---|---|
6d0dff49 JW |
1 | // Copyright (C) 2019 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 run { target c++2a } } | |
20 | ||
328b52d6 | 21 | #include <ranges> |
6d0dff49 JW |
22 | #include <testsuite_hooks.h> |
23 | using std::same_as; | |
24 | ||
25 | void | |
26 | test01() | |
27 | { | |
28 | int a[2] = {}; | |
29 | ||
30 | static_assert(same_as<decltype(std::ranges::cbegin(a)), const int*>); | |
31 | static_assert(noexcept(std::ranges::cbegin(a))); | |
32 | VERIFY( std::ranges::cbegin(a) == (a + 0) ); | |
33 | ||
34 | constexpr long b[2] = {}; | |
35 | static_assert( std::ranges::cbegin(b) == (b + 0) ); | |
36 | } | |
37 | ||
38 | struct R | |
39 | { | |
40 | int a[4] = { 0, 1, 2, 3 }; | |
41 | ||
42 | friend int* begin(R& r) { return r.a + 0; } | |
43 | friend int* begin(R&& r) { return r.a + 1; } | |
44 | friend const int* begin(const R& r) noexcept { return r.a + 2; } | |
45 | friend const int* begin(const R&& r) noexcept { return r.a + 3; } | |
46 | }; | |
47 | ||
48 | void | |
49 | test03() | |
50 | { | |
51 | R r; | |
52 | const R& c = r; | |
53 | VERIFY(std::ranges::cbegin(r) == std::ranges::begin(c)); | |
54 | VERIFY(std::ranges::cbegin(std::move(r)) == std::ranges::begin(std::move(c))); | |
55 | VERIFY(std::ranges::cbegin(c) == std::ranges::begin(c)); | |
56 | VERIFY(std::ranges::cbegin(std::move(c)) == std::ranges::begin(std::move(c))); | |
57 | } | |
58 | ||
59 | struct RR | |
60 | { | |
61 | short s = 0; | |
62 | long l = 0; | |
63 | int a[4] = { 0, 1, 2, 3 }; | |
64 | ||
65 | short* begin() noexcept { return &s; } | |
66 | const long* begin() const { return &l; } | |
67 | ||
68 | friend int* begin(RR& r) { return r.a + 0; } | |
69 | friend int* begin(RR&& r) { return r.a + 1; } | |
70 | friend const int* begin(const RR& r) { return r.a + 2; } | |
71 | friend const int* begin(const RR&& r) noexcept { return r.a + 3; } | |
72 | }; | |
73 | ||
74 | void | |
75 | test04() | |
76 | { | |
77 | RR r; | |
78 | const RR& c = r; | |
79 | VERIFY(std::ranges::cbegin(r) == std::ranges::begin(c)); | |
80 | VERIFY(std::ranges::cbegin(std::move(r)) == std::ranges::begin(std::move(c))); | |
81 | VERIFY(std::ranges::cbegin(c) == std::ranges::begin(c)); | |
82 | VERIFY(std::ranges::cbegin(std::move(c)) == std::ranges::begin(std::move(c))); | |
83 | } | |
84 | ||
85 | int | |
86 | main() | |
87 | { | |
88 | test01(); | |
89 | test03(); | |
90 | test04(); | |
91 | } |