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