]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/erase/1.cc
1 // 2005-12-23 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2024 Free Software Foundation, Inc.
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)
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.
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/>.
20 // 23.2.5 vector<bool> modifiers
23 #include <testsuite_hooks.h>
25 const bool A
[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
26 const bool A1
[] = {0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
27 const bool A2
[] = {0, 0, 1, 0, 0, 1, 0, 1, 0, 1};
28 const bool A3
[] = {0, 0, 1, 0, 0, 1};
29 const bool A4
[] = {0, 0, 1};
30 const bool A5
[] = {0, 0};
32 const unsigned N
= sizeof(A
) / sizeof(bool);
33 const unsigned N1
= sizeof(A1
) / sizeof(bool);
34 const unsigned N2
= sizeof(A2
) / sizeof(bool);
35 const unsigned N3
= sizeof(A3
) / sizeof(bool);
36 const unsigned N4
= sizeof(A4
) / sizeof(bool);
37 const unsigned N5
= sizeof(A5
) / sizeof(bool);
42 typedef std::vector
<bool> vec_type
;
43 typedef vec_type::iterator iterator_type
;
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
) );
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
) );
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
) );
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
) );
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
) );
72 iterator_type it6
= v
.erase(v
.begin(), v
.end());
73 VERIFY( it6
== v
.begin() );
80 typedef std::vector
<std::vector
<bool> > vec_type
;
81 typedef vec_type::iterator iterator_type
;
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
]));
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()) );
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()) );
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()) );
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()) );
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()) );
122 iterator_type it6
= v
.erase(v
.begin(), v
.end());
123 VERIFY( it6
== v
.begin() );