1// { dg-do run } 2// { dg-options "-std=gnu++14" } 3 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. 11 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. 16 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/>. 20 21// 24.6.5, range access [iterator.range] 22 23#include <iterator> 24#include <vector> 25#include <testsuite_hooks.h> 26 27bool test __attribute__((unused)) = true; 28 29void 30test01() 31{ 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)); 39} 40 41void 42test02() 43{ 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); 49} 50 51int 52test03() 53{ 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())); 61} 62 63int 64test04() 65{ 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()); 73} 74 75int 76main() 77{ 78 test01(); 79 test02(); 80 test03(); 81 test04(); 82} 83