]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc
re PR libstdc++/28587 (vector<bool> is extremely slow (900x slower than it should...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / bool / capacity / 1.cc
1 // 2006-08-05 Paolo Carlini <pcarlini@suse.de>
2
3 // Copyright (C) 2006 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.5 vector<bool> resize
22
23 #include <vector>
24 #include <testsuite_hooks.h>
25
26 const bool A1[] = {0};
27 const bool A2[] = {0, 0, 0};
28 const bool A3[] = {0, 0};
29 const bool A4[] = {0, 0, 1, 1, 1, 1, 1};
30 const bool A5[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
31 const bool A6[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
33 1, 1, 1, 1};
34 const bool A7[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
36 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 1, 1, 1, 1, 1,
56 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
57 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
58 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
59 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
60 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
61 1, 1};
62 const bool A11[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0};
63
64 const unsigned N1 = sizeof(A1) / sizeof(bool);
65 const unsigned N2 = sizeof(A2) / sizeof(bool);
66 const unsigned N3 = sizeof(A3) / sizeof(bool);
67 const unsigned N4 = sizeof(A4) / sizeof(bool);
68 const unsigned N5 = sizeof(A5) / sizeof(bool);
69 const unsigned N6 = sizeof(A6) / sizeof(bool);
70 const unsigned N7 = sizeof(A7) / sizeof(bool);
71 const unsigned N8 = sizeof(A8) / sizeof(bool);
72 const unsigned N9 = sizeof(A9) / sizeof(bool);
73 const unsigned N10 = sizeof(A10) / sizeof(bool);
74 const unsigned N11 = sizeof(A11) / sizeof(bool);
75
76 void
77 test01()
78 {
79 bool test __attribute__((unused)) = true;
80
81 typedef std::vector<bool> vec_type;
82
83 vec_type v;
84
85 v.resize(1);
86 VERIFY( v.size() == 1 );
87 VERIFY( std::equal(v.begin(), v.end(), A1) );
88
89 v.resize(3);
90 VERIFY( v.size() == 3 );
91 VERIFY( std::equal(v.begin(), v.end(), A2) );
92
93 v.resize(2);
94 VERIFY( v.size() == 2 );
95 VERIFY( std::equal(v.begin(), v.end(), A3) );
96
97 v.resize(7, true);
98 VERIFY( v.size() == 7 );
99 VERIFY( std::equal(v.begin(), v.end(), A4) );
100
101 v.resize(18, false);
102 VERIFY( v.size() == 18 );
103 VERIFY( std::equal(v.begin(), v.end(), A5) );
104
105 v.resize(40, true);
106 VERIFY( v.size() == 40 );
107 VERIFY( std::equal(v.begin(), v.end(), A6) );
108
109 v.resize(80, false);
110 VERIFY( v.size() == 80 );
111 VERIFY( std::equal(v.begin(), v.end(), A7) );
112
113 v.resize(90, true);
114 VERIFY( v.size() == 90 );
115 VERIFY( std::equal(v.begin(), v.end(), A8) );
116
117 v.resize(100, false);
118 VERIFY( v.size() == 100 );
119 VERIFY( std::equal(v.begin(), v.end(), A9) );
120
121 v.resize(200, true);
122 VERIFY( v.size() == 200 );
123 VERIFY( std::equal(v.begin(), v.end(), A10) );
124
125 v.resize(13, true);
126 VERIFY( v.size() == 13 );
127 VERIFY( std::equal(v.begin(), v.end(), A11) );
128
129 v.resize(13, false);
130 VERIFY( v.size() == 13 );
131 VERIFY( std::equal(v.begin(), v.end(), A11) );
132 }
133
134 int main()
135 {
136 test01();
137 return 0;
138 }