1// 2005-11-25 Paolo Carlini <pcarlini@suse.de> 2 3// Copyright (C) 2005-2015 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// 23.2.1.3 deque modifiers 21 22#include <deque> 23#include <testsuite_hooks.h> 24 25const int A[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 26 13, 14, 15}; 27const int A0[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 28const int A1[] = {-5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; 29const int A2[] = {-5, 0, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15}; 30const int A3[] = {-5, 0, 1, 2, 8, 9, 10, 11}; 31const int A4[] = {2, 8, 9, 10, 11}; 32const int A5[] = {2, 8, 10, 11}; 33const int A6[] = {2, 8, 10}; 34const unsigned N = sizeof(A) / sizeof(int); 35const unsigned N0 = sizeof(A0) / sizeof(int); 36const unsigned N1 = sizeof(A1) / sizeof(int); 37const unsigned N2 = sizeof(A2) / sizeof(int); 38const unsigned N3 = sizeof(A3) / sizeof(int); 39const unsigned N4 = sizeof(A4) / sizeof(int); 40const unsigned N5 = sizeof(A5) / sizeof(int); 41const unsigned N6 = sizeof(A6) / sizeof(int); 42 43template<int Size> 44 class My_class 45 { 46 double dummy[Size]; 47 int data; 48 49 public: 50 My_class(int num) 51 : data(num) { } 52 53 operator int() const 54 { return data; } 55 }; 56 57template<typename T> 58 void 59 test01() 60 { 61 bool test __attribute__((unused)) = true; 62 63 typedef std::deque<T> deque_type; 64 typedef typename deque_type::iterator iterator_type; 65 66 deque_type v(A, A + N); 67 68 iterator_type it0 = v.erase(v.begin() + 1, v.begin() + 4); 69 VERIFY( it0 == v.begin() + 1 ); 70 VERIFY( v.size() == N0 ); 71 VERIFY( std::equal(v.begin(), v.end(), A0) ); 72 73 iterator_type it1 = v.erase(v.begin() + 1); 74 VERIFY( it1 == v.begin() + 1 ); 75 VERIFY( v.size() == N1 ); 76 VERIFY( std::equal(v.begin(), v.end(), A1) ); 77 78 iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9); 79 VERIFY( it2 == v.begin() + 4 ); 80 VERIFY( v.size() == N2 ); 81 VERIFY( std::equal(v.begin(), v.end(), A2) ); 82 83 iterator_type it3 = v.erase(v.begin() + 8, v.end()); 84 VERIFY( it3 == v.begin() + 8 ); 85 VERIFY( v.size() == N3 ); 86 VERIFY( std::equal(v.begin(), v.end(), A3) ); 87 88 iterator_type it4 = v.erase(v.begin(), v.begin() + 3); 89 VERIFY( it4 == v.begin() ); 90 VERIFY( v.size() == N4 ); 91 VERIFY( std::equal(v.begin(), v.end(), A4) ); 92 93 iterator_type it5 = v.erase(v.begin() + 2); 94 VERIFY( it5 == v.begin() + 2 ); 95 VERIFY( v.size() == N5 ); 96 VERIFY( std::equal(v.begin(), v.end(), A5) ); 97 98 iterator_type it6 = v.erase(v.begin() + 3, v.end()); 99 VERIFY( it6 == v.begin() + 3 ); 100 VERIFY( v.size() == N6 ); 101 VERIFY( std::equal(v.begin(), v.end(), A6) ); 102 103 iterator_type it7 = v.erase(v.begin(), v.end()); 104 VERIFY( it7 == v.begin() ); 105 VERIFY( v.empty() ); 106 } 107 108int main() 109{ 110 test01<My_class<1> >(); 111 test01<My_class<8> >(); 112 test01<My_class<32> >(); 113 return 0; 114} 115