1// 2005-12-23  Paolo Carlini  <pcarlini@suse.de>
2
3// Copyright (C) 2005, 2006, 2009 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.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{
42  bool test __attribute__((unused)) = true;
43
44  typedef std::vector<bool>  vec_type;
45  typedef vec_type::iterator iterator_type;
46
47  vec_type v(A, A + N);
48
49  iterator_type it1 = v.erase(v.begin() + 1);
50  VERIFY( it1 == v.begin() + 1 );
51  VERIFY( v.size() == N1 );
52  VERIFY( std::equal(v.begin(), v.end(), A1) );
53
54  iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
55  VERIFY( it2 == v.begin() + 4 );
56  VERIFY( v.size() == N2 );
57  VERIFY( std::equal(v.begin(), v.end(), A2) );
58
59  iterator_type it3 = v.erase(v.begin() + 6, v.end());
60  VERIFY( it3 == v.begin() + 6 );
61  VERIFY( v.size() == N3 );
62  VERIFY( std::equal(v.begin(), v.end(), A3) );
63
64  iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
65  VERIFY( it4 == v.begin() );
66  VERIFY( v.size() == N4 );
67  VERIFY( std::equal(v.begin(), v.end(), A4) );
68
69  iterator_type it5 = v.erase(v.begin() + 2);
70  VERIFY( it5 == v.begin() + 2 );
71  VERIFY( v.size() == N5 );
72  VERIFY( std::equal(v.begin(), v.end(), A5) );
73
74  iterator_type it6 = v.erase(v.begin(), v.end());
75  VERIFY( it6 == v.begin() );
76  VERIFY( v.empty() );
77}
78
79void
80test02()
81{
82  bool test __attribute__((unused)) = true;
83
84  typedef std::vector<std::vector<bool> >  vec_type;
85  typedef vec_type::iterator          iterator_type;
86
87  vec_type v, v1, v2, v3, v4, v5;
88  for (unsigned i = 0; i < N; ++i)
89    v.push_back(std::vector<bool>(1, A[i]));
90  for (unsigned i = 0; i < N1; ++i)
91    v1.push_back(std::vector<bool>(1, A1[i]));
92  for (unsigned i = 0; i < N2; ++i)
93    v2.push_back(std::vector<bool>(1, A2[i]));
94  for (unsigned i = 0; i < N3; ++i)
95    v3.push_back(std::vector<bool>(1, A3[i]));
96  for (unsigned i = 0; i < N4; ++i)
97    v4.push_back(std::vector<bool>(1, A4[i]));
98  for (unsigned i = 0; i < N5; ++i)
99    v5.push_back(std::vector<bool>(1, A5[i]));
100
101  iterator_type it1 = v.erase(v.begin() + 1);
102  VERIFY( it1 == v.begin() + 1 );
103  VERIFY( v.size() == N1 );
104  VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
105
106  iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
107  VERIFY( it2 == v.begin() + 4 );
108  VERIFY( v.size() == N2 );
109  VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
110
111  iterator_type it3 = v.erase(v.begin() + 6, v.end());
112  VERIFY( it3 == v.begin() + 6 );
113  VERIFY( v.size() == N3 );
114  VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
115
116  iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
117  VERIFY( it4 == v.begin() );
118  VERIFY( v.size() == N4 );
119  VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
120
121  iterator_type it5 = v.erase(v.begin() + 2);
122  VERIFY( it5 == v.begin() + 2 );
123  VERIFY( v.size() == N5 );
124  VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
125
126  iterator_type it6 = v.erase(v.begin(), v.end());
127  VERIFY( it6 == v.begin() );
128  VERIFY( v.empty() );
129}
130
131int main()
132{
133  test01();
134  test02();
135  return 0;
136}
137