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