re PR libfortran/69799 (FAIL: gfortran.dg/coarray_allocate_3.f08 at -O1 and above)
[official-gcc.git] / libstdc++-v3 / testsuite / 24_iterators / range_access_cpp14.cc
blob9292fa65d19904e4f1e224044becf5c20b820b24
1 // { dg-do run }
2 // { dg-options "-std=gnu++14" }
4 // Copyright (C) 2015-2016 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 24.6.5, range access [iterator.range]
23 #include <iterator>
24 #include <vector>
25 #include <testsuite_hooks.h>
27 bool test __attribute__((unused)) = true;
29 void
30 test01()
32 int i[1];
33 VERIFY(std::cbegin(i) == i);
34 VERIFY(std::cend(i) == i+1);
35 VERIFY(std::rbegin(i) == std::reverse_iterator<int*>(i+1));
36 VERIFY(std::rend(i) == std::reverse_iterator<int*>(i));
37 VERIFY(std::crbegin(i) == std::reverse_iterator<int*>(i+1));
38 VERIFY(std::crend(i) == std::reverse_iterator<int*>(i));
41 void
42 test02()
44 static int i[1];
45 constexpr auto b __attribute__((unused)) = std::begin(i);
46 constexpr auto e __attribute__((unused)) = std::end(i);
47 constexpr auto cb __attribute__((unused)) = std::cbegin(i);
48 constexpr auto ce __attribute__((unused)) = std::cend(i);
51 int
52 test03()
54 std::initializer_list<int> il{1};
55 VERIFY(std::cbegin(il) == il.begin());
56 VERIFY(std::cend(il) == il.end());
57 VERIFY(std::rbegin(il) == std::reverse_iterator<const int*>(il.end()));
58 VERIFY(std::rend(il) == std::reverse_iterator<const int*>(il.begin()));
59 VERIFY(std::crbegin(il) == std::reverse_iterator<const int*>(il.end()));
60 VERIFY(std::crend(il) == std::reverse_iterator<const int*>(il.begin()));
63 int
64 test04()
66 std::vector<int> v{1};
67 VERIFY(std::cbegin(v) == v.cbegin());
68 VERIFY(std::cend(v) == v.cend());
69 VERIFY(std::rbegin(v) == v.rbegin());
70 VERIFY(std::rend(v) == v.rend());
71 VERIFY(std::crbegin(v) == v.crbegin());
72 VERIFY(std::crend(v) == v.crend());
75 int
76 main()
78 test01();
79 test02();
80 test03();
81 test04();