]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/24_iterators/range_access_cpp14.cc
Use effective-target instead of -std options
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 24_iterators / range_access_cpp14.cc
1 // { dg-do run { target c++14 } }
2
3 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
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
20 // 24.6.5, range access [iterator.range]
21
22 #include <iterator>
23 #include <vector>
24 #include <testsuite_hooks.h>
25
26 bool test __attribute__((unused)) = true;
27
28 void
29 test01()
30 {
31 int i[1];
32 VERIFY(std::cbegin(i) == i);
33 VERIFY(std::cend(i) == i+1);
34 VERIFY(std::rbegin(i) == std::reverse_iterator<int*>(i+1));
35 VERIFY(std::rend(i) == std::reverse_iterator<int*>(i));
36 VERIFY(std::crbegin(i) == std::reverse_iterator<int*>(i+1));
37 VERIFY(std::crend(i) == std::reverse_iterator<int*>(i));
38 }
39
40 void
41 test02()
42 {
43 static int i[1];
44 constexpr auto b __attribute__((unused)) = std::begin(i);
45 constexpr auto e __attribute__((unused)) = std::end(i);
46 constexpr auto cb __attribute__((unused)) = std::cbegin(i);
47 constexpr auto ce __attribute__((unused)) = std::cend(i);
48 }
49
50 void
51 test03()
52 {
53 std::initializer_list<int> il{1};
54 VERIFY(std::cbegin(il) == il.begin());
55 VERIFY(std::cend(il) == il.end());
56 VERIFY(std::rbegin(il) == std::reverse_iterator<const int*>(il.end()));
57 VERIFY(std::rend(il) == std::reverse_iterator<const int*>(il.begin()));
58 VERIFY(std::crbegin(il) == std::reverse_iterator<const int*>(il.end()));
59 VERIFY(std::crend(il) == std::reverse_iterator<const int*>(il.begin()));
60 }
61
62 void
63 test04()
64 {
65 std::vector<int> v{1};
66 VERIFY(std::cbegin(v) == v.cbegin());
67 VERIFY(std::cend(v) == v.cend());
68 VERIFY(std::rbegin(v) == v.rbegin());
69 VERIFY(std::rend(v) == v.rend());
70 VERIFY(std::crbegin(v) == v.crbegin());
71 VERIFY(std::crend(v) == v.crend());
72 }
73
74 int
75 main()
76 {
77 test01();
78 test02();
79 test03();
80 test04();
81 }