]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++14 } } |
8bae22b7 | 2 | |
99dee823 | 3 | // Copyright (C) 2015-2021 Free Software Foundation, Inc. |
8bae22b7 VV |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
2c0378f4 | 20 | // C++ 2014 24.7, range access [iterator.range] |
8bae22b7 VV |
21 | |
22 | #include <iterator> | |
23 | #include <vector> | |
24 | #include <testsuite_hooks.h> | |
25 | ||
8bae22b7 VV |
26 | void |
27 | test01() | |
28 | { | |
29 | int i[1]; | |
30 | VERIFY(std::cbegin(i) == i); | |
31 | VERIFY(std::cend(i) == i+1); | |
32 | VERIFY(std::rbegin(i) == std::reverse_iterator<int*>(i+1)); | |
33 | VERIFY(std::rend(i) == std::reverse_iterator<int*>(i)); | |
34 | VERIFY(std::crbegin(i) == std::reverse_iterator<int*>(i+1)); | |
35 | VERIFY(std::crend(i) == std::reverse_iterator<int*>(i)); | |
36 | } | |
37 | ||
38 | void | |
39 | test02() | |
40 | { | |
41 | static int i[1]; | |
42 | constexpr auto b __attribute__((unused)) = std::begin(i); | |
43 | constexpr auto e __attribute__((unused)) = std::end(i); | |
44 | constexpr auto cb __attribute__((unused)) = std::cbegin(i); | |
45 | constexpr auto ce __attribute__((unused)) = std::cend(i); | |
46 | } | |
47 | ||
0a024155 | 48 | void |
8bae22b7 VV |
49 | test03() |
50 | { | |
51 | std::initializer_list<int> il{1}; | |
52 | VERIFY(std::cbegin(il) == il.begin()); | |
53 | VERIFY(std::cend(il) == il.end()); | |
54 | VERIFY(std::rbegin(il) == std::reverse_iterator<const int*>(il.end())); | |
55 | VERIFY(std::rend(il) == std::reverse_iterator<const int*>(il.begin())); | |
56 | VERIFY(std::crbegin(il) == std::reverse_iterator<const int*>(il.end())); | |
57 | VERIFY(std::crend(il) == std::reverse_iterator<const int*>(il.begin())); | |
58 | } | |
59 | ||
0a024155 | 60 | void |
8bae22b7 VV |
61 | test04() |
62 | { | |
63 | std::vector<int> v{1}; | |
64 | VERIFY(std::cbegin(v) == v.cbegin()); | |
65 | VERIFY(std::cend(v) == v.cend()); | |
66 | VERIFY(std::rbegin(v) == v.rbegin()); | |
67 | VERIFY(std::rend(v) == v.rend()); | |
68 | VERIFY(std::crbegin(v) == v.crbegin()); | |
69 | VERIFY(std::crend(v) == v.crend()); | |
70 | } | |
71 | ||
72 | int | |
73 | main() | |
74 | { | |
75 | test01(); | |
76 | test02(); | |
77 | test03(); | |
78 | test04(); | |
79 | } |