]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/vector/modifiers/erase/1.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / modifiers / erase / 1.cc
CommitLineData
bc9053ab
PC
1// 2005-11-02 Paolo Carlini <pcarlini@suse.de>
2
aa118a03 3// Copyright (C) 2005-2014 Free Software Foundation, Inc.
bc9053ab
PC
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
bc9053ab
PC
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
bc9053ab
PC
19
20// 23.2.4.3 vector modifiers
21
22#include <vector>
23#include <testsuite_hooks.h>
24
25const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
26const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
27const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15};
28const int A3[] = {0, 2, 3, 4, 10, 11};
29const int A4[] = {4, 10, 11};
30const int A5[] = {4, 10};
8b5bc374
CJ
31const unsigned int N = sizeof(A) / sizeof(int);
32const unsigned int N1 = sizeof(A1) / sizeof(int);
33const unsigned int N2 = sizeof(A2) / sizeof(int);
34const unsigned int N3 = sizeof(A3) / sizeof(int);
35const unsigned int N4 = sizeof(A4) / sizeof(int);
36const unsigned int N5 = sizeof(A5) / sizeof(int);
bc9053ab
PC
37
38void
39test01()
40{
41 bool test __attribute__((unused)) = true;
42
43 typedef std::vector<int> vec_type;
44 typedef vec_type::iterator iterator_type;
45
46 vec_type v(A, A + N);
47
48 iterator_type it1 = v.erase(v.begin() + 1);
49 VERIFY( it1 == v.begin() + 1 );
50 VERIFY( v.size() == N1 );
51 VERIFY( std::equal(v.begin(), v.end(), A1) );
52
53 iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
54 VERIFY( it2 == v.begin() + 4 );
55 VERIFY( v.size() == N2 );
56 VERIFY( std::equal(v.begin(), v.end(), A2) );
57
58 iterator_type it3 = v.erase(v.begin() + 6, v.end());
59 VERIFY( it3 == v.begin() + 6 );
60 VERIFY( v.size() == N3 );
61 VERIFY( std::equal(v.begin(), v.end(), A3) );
62
63 iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
64 VERIFY( it4 == v.begin() );
65 VERIFY( v.size() == N4 );
66 VERIFY( std::equal(v.begin(), v.end(), A4) );
67
68 iterator_type it5 = v.erase(v.begin() + 2);
69 VERIFY( it5 == v.begin() + 2 );
70 VERIFY( v.size() == N5 );
71 VERIFY( std::equal(v.begin(), v.end(), A5) );
72
73 iterator_type it6 = v.erase(v.begin(), v.end());
74 VERIFY( it6 == v.begin() );
75 VERIFY( v.empty() );
76}
77
78void
79test02()
80{
81 bool test __attribute__((unused)) = true;
82
83 typedef std::vector<std::vector<int> > vec_type;
84 typedef vec_type::iterator iterator_type;
85
86 vec_type v, v1, v2, v3, v4, v5;
8b5bc374 87 for (unsigned int i = 0; i < N; ++i)
bc9053ab 88 v.push_back(std::vector<int>(1, A[i]));
8b5bc374 89 for (unsigned int i = 0; i < N1; ++i)
bc9053ab 90 v1.push_back(std::vector<int>(1, A1[i]));
8b5bc374 91 for (unsigned int i = 0; i < N2; ++i)
bc9053ab 92 v2.push_back(std::vector<int>(1, A2[i]));
8b5bc374 93 for (unsigned int i = 0; i < N3; ++i)
bc9053ab 94 v3.push_back(std::vector<int>(1, A3[i]));
8b5bc374 95 for (unsigned int i = 0; i < N4; ++i)
bc9053ab 96 v4.push_back(std::vector<int>(1, A4[i]));
8b5bc374 97 for (unsigned int i = 0; i < N5; ++i)
bc9053ab
PC
98 v5.push_back(std::vector<int>(1, A5[i]));
99
100 iterator_type it1 = v.erase(v.begin() + 1);
101 VERIFY( it1 == v.begin() + 1 );
102 VERIFY( v.size() == N1 );
103 VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
104
105 iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
106 VERIFY( it2 == v.begin() + 4 );
107 VERIFY( v.size() == N2 );
108 VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
109
110 iterator_type it3 = v.erase(v.begin() + 6, v.end());
111 VERIFY( it3 == v.begin() + 6 );
112 VERIFY( v.size() == N3 );
113 VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
114
115 iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
116 VERIFY( it4 == v.begin() );
117 VERIFY( v.size() == N4 );
118 VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
119
120 iterator_type it5 = v.erase(v.begin() + 2);
121 VERIFY( it5 == v.begin() + 2 );
122 VERIFY( v.size() == N5 );
123 VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
124
125 iterator_type it6 = v.erase(v.begin(), v.end());
126 VERIFY( it6 == v.begin() );
127 VERIFY( v.empty() );
128}
129
130int main()
131{
132 test01();
133 test02();
134 return 0;
135}