]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/2.cc
1 // 2005-12-23 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2023 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>::swap
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // uneq_allocator, two different personalities.
32 typedef __gnu_test::uneq_allocator
<bool> my_alloc
;
33 typedef vector
<bool, my_alloc
> my_vector
;
35 const char title01
[] = "Rivers of sand";
36 const char title02
[] = "Concret PH";
37 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
38 const char title04
[] = "never as tired as when i'm waking up";
40 const size_t N1
= sizeof(title01
);
41 const size_t N2
= sizeof(title02
);
42 const size_t N3
= sizeof(title03
);
43 const size_t N4
= sizeof(title04
);
45 vector
<bool> vec01_ref
;
46 for (size_t i
= 0; i
< N1
; ++i
)
47 vec01_ref
.push_back(bool(title01
[i
] > 96 ? 1 : 0));
48 vector
<bool> vec02_ref
;
49 for (size_t i
= 0; i
< N2
; ++i
)
50 vec02_ref
.push_back(bool(title02
[i
] > 96 ? 1 : 0));
51 vector
<bool> vec03_ref
;
52 for (size_t i
= 0; i
< N3
; ++i
)
53 vec03_ref
.push_back(bool(title03
[i
] > 96 ? 1 : 0));
54 vector
<bool> vec04_ref
;
55 for (size_t i
= 0; i
< N4
; ++i
)
56 vec04_ref
.push_back(bool(title04
[i
] > 96 ? 1 : 0));
58 my_vector::size_type size01
, size02
;
60 my_alloc
alloc01(1), alloc02(2);
61 int personality01
, personality02
;
63 my_vector
vec01(alloc01
);
64 size01
= vec01
.size();
65 personality01
= vec01
.get_allocator().get_personality();
66 my_vector
vec02(alloc02
);
67 size02
= vec02
.size();
68 personality02
= vec02
.get_allocator().get_personality();
71 VERIFY( vec01
.size() == size02
);
72 VERIFY( vec01
.empty() );
73 VERIFY( vec02
.size() == size01
);
74 VERIFY( vec02
.empty() );
75 VERIFY( vec01
.get_allocator().get_personality() == personality02
);
76 VERIFY( vec02
.get_allocator().get_personality() == personality01
);
78 my_vector
vec03(alloc02
);
79 size01
= vec03
.size();
80 personality01
= vec03
.get_allocator().get_personality();
81 my_vector
vec04(vec02_ref
.begin(), vec02_ref
.end(), alloc01
);
82 size02
= vec04
.size();
83 personality02
= vec04
.get_allocator().get_personality();
86 VERIFY( vec03
.size() == size02
);
87 VERIFY( equal(vec03
.begin(), vec03
.end(), vec02_ref
.begin()) );
88 VERIFY( vec04
.size() == size01
);
89 VERIFY( vec04
.empty() );
90 VERIFY( vec03
.get_allocator().get_personality() == personality02
);
91 VERIFY( vec04
.get_allocator().get_personality() == personality01
);
93 my_vector
vec05(vec01_ref
.begin(), vec01_ref
.end(), alloc01
);
94 size01
= vec05
.size();
95 personality01
= vec05
.get_allocator().get_personality();
96 my_vector
vec06(vec02_ref
.begin(), vec02_ref
.end(), alloc02
);
97 size02
= vec06
.size();
98 personality02
= vec06
.get_allocator().get_personality();
101 VERIFY( vec05
.size() == size02
);
102 VERIFY( equal(vec05
.begin(), vec05
.end(), vec02_ref
.begin()) );
103 VERIFY( vec06
.size() == size01
);
104 VERIFY( equal(vec06
.begin(), vec06
.end(), vec01_ref
.begin()) );
105 VERIFY( vec05
.get_allocator().get_personality() == personality02
);
106 VERIFY( vec06
.get_allocator().get_personality() == personality01
);
108 my_vector
vec07(vec01_ref
.begin(), vec01_ref
.end(), alloc02
);
109 size01
= vec07
.size();
110 personality01
= vec07
.get_allocator().get_personality();
111 my_vector
vec08(vec03_ref
.begin(), vec03_ref
.end(), alloc01
);
112 size02
= vec08
.size();
113 personality02
= vec08
.get_allocator().get_personality();
116 VERIFY( vec07
.size() == size02
);
117 VERIFY( equal(vec07
.begin(), vec07
.end(), vec03_ref
.begin()) );
118 VERIFY( vec08
.size() == size01
);
119 VERIFY( equal(vec08
.begin(), vec08
.end(), vec01_ref
.begin()) );
120 VERIFY( vec07
.get_allocator().get_personality() == personality02
);
121 VERIFY( vec08
.get_allocator().get_personality() == personality01
);
123 my_vector
vec09(vec03_ref
.begin(), vec03_ref
.end(), alloc01
);
124 size01
= vec09
.size();
125 personality01
= vec09
.get_allocator().get_personality();
126 my_vector
vec10(vec04_ref
.begin(), vec04_ref
.end(), alloc02
);
127 size02
= vec10
.size();
128 personality02
= vec10
.get_allocator().get_personality();
131 VERIFY( vec09
.size() == size02
);
132 VERIFY( equal(vec09
.begin(), vec09
.end(), vec04_ref
.begin()) );
133 VERIFY( vec10
.size() == size01
);
134 VERIFY( equal(vec10
.begin(), vec10
.end(), vec03_ref
.begin()) );
135 VERIFY( vec09
.get_allocator().get_personality() == personality02
);
136 VERIFY( vec10
.get_allocator().get_personality() == personality01
);
138 my_vector
vec11(vec04_ref
.begin(), vec04_ref
.end(), alloc02
);
139 size01
= vec11
.size();
140 personality01
= vec11
.get_allocator().get_personality();
141 my_vector
vec12(vec01_ref
.begin(), vec01_ref
.end(), alloc01
);
142 size02
= vec12
.size();
143 personality02
= vec12
.get_allocator().get_personality();
146 VERIFY( vec11
.size() == size02
);
147 VERIFY( equal(vec11
.begin(), vec11
.end(), vec01_ref
.begin()) );
148 VERIFY( vec12
.size() == size01
);
149 VERIFY( equal(vec12
.begin(), vec12
.end(), vec04_ref
.begin()) );
150 VERIFY( vec11
.get_allocator().get_personality() == personality02
);
151 VERIFY( vec12
.get_allocator().get_personality() == personality01
);
153 my_vector
vec13(vec03_ref
.begin(), vec03_ref
.end(), alloc01
);
154 size01
= vec13
.size();
155 personality01
= vec13
.get_allocator().get_personality();
156 my_vector
vec14(vec03_ref
.begin(), vec03_ref
.end(), alloc02
);
157 size02
= vec14
.size();
158 personality02
= vec14
.get_allocator().get_personality();
161 VERIFY( vec13
.size() == size02
);
162 VERIFY( equal(vec13
.begin(), vec13
.end(), vec03_ref
.begin()) );
163 VERIFY( vec14
.size() == size01
);
164 VERIFY( equal(vec14
.begin(), vec14
.end(), vec03_ref
.begin()) );
165 VERIFY( vec13
.get_allocator().get_personality() == personality02
);
166 VERIFY( vec14
.get_allocator().get_personality() == personality01
);