2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 24_iterators / range_access_cpp14.cc
bloba75e04cef9a3af2b53940e6f4172efd9db0eca07
1 // { dg-do run }
2 // { dg-options "-std=gnu++14" }
4 // Copyright (C) 2015 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();