Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / 23_containers / vector / bool / modifiers / swap / 2.cc
blob606254bad7c7a0f219a0afe7d96f0128d7f8e3bb
1 // 2005-12-23 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005, 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.
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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 23.2.5 vector<bool>::swap
23 #include <vector>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator, two different personalities.
28 void
29 test01()
31 bool test __attribute__((unused)) = true;
32 using namespace std;
34 typedef __gnu_test::uneq_allocator<bool> my_alloc;
35 typedef vector<bool, my_alloc> my_vector;
37 const char title01[] = "Rivers of sand";
38 const char title02[] = "Concret PH";
39 const char title03[] = "Sonatas and Interludes for Prepared Piano";
40 const char title04[] = "never as tired as when i'm waking up";
42 const size_t N1 = sizeof(title01);
43 const size_t N2 = sizeof(title02);
44 const size_t N3 = sizeof(title03);
45 const size_t N4 = sizeof(title04);
47 vector<bool> vec01_ref;
48 for (size_t i = 0; i < N1; ++i)
49 vec01_ref.push_back(bool(title01[i] > 96 ? 1 : 0));
50 vector<bool> vec02_ref;
51 for (size_t i = 0; i < N2; ++i)
52 vec02_ref.push_back(bool(title02[i] > 96 ? 1 : 0));
53 vector<bool> vec03_ref;
54 for (size_t i = 0; i < N3; ++i)
55 vec03_ref.push_back(bool(title03[i] > 96 ? 1 : 0));
56 vector<bool> vec04_ref;
57 for (size_t i = 0; i < N4; ++i)
58 vec04_ref.push_back(bool(title04[i] > 96 ? 1 : 0));
60 my_vector::size_type size01, size02;
62 my_alloc alloc01(1), alloc02(2);
63 int personality01, personality02;
65 my_vector vec01(alloc01);
66 size01 = vec01.size();
67 personality01 = vec01.get_allocator().get_personality();
68 my_vector vec02(alloc02);
69 size02 = vec02.size();
70 personality02 = vec02.get_allocator().get_personality();
72 vec01.swap(vec02);
73 VERIFY( vec01.size() == size02 );
74 VERIFY( vec01.empty() );
75 VERIFY( vec02.size() == size01 );
76 VERIFY( vec02.empty() );
77 VERIFY( vec01.get_allocator().get_personality() == personality02 );
78 VERIFY( vec02.get_allocator().get_personality() == personality01 );
80 my_vector vec03(alloc02);
81 size01 = vec03.size();
82 personality01 = vec03.get_allocator().get_personality();
83 my_vector vec04(vec02_ref.begin(), vec02_ref.end(), alloc01);
84 size02 = vec04.size();
85 personality02 = vec04.get_allocator().get_personality();
87 vec03.swap(vec04);
88 VERIFY( vec03.size() == size02 );
89 VERIFY( equal(vec03.begin(), vec03.end(), vec02_ref.begin()) );
90 VERIFY( vec04.size() == size01 );
91 VERIFY( vec04.empty() );
92 VERIFY( vec03.get_allocator().get_personality() == personality02 );
93 VERIFY( vec04.get_allocator().get_personality() == personality01 );
95 my_vector vec05(vec01_ref.begin(), vec01_ref.end(), alloc01);
96 size01 = vec05.size();
97 personality01 = vec05.get_allocator().get_personality();
98 my_vector vec06(vec02_ref.begin(), vec02_ref.end(), alloc02);
99 size02 = vec06.size();
100 personality02 = vec06.get_allocator().get_personality();
102 vec05.swap(vec06);
103 VERIFY( vec05.size() == size02 );
104 VERIFY( equal(vec05.begin(), vec05.end(), vec02_ref.begin()) );
105 VERIFY( vec06.size() == size01 );
106 VERIFY( equal(vec06.begin(), vec06.end(), vec01_ref.begin()) );
107 VERIFY( vec05.get_allocator().get_personality() == personality02 );
108 VERIFY( vec06.get_allocator().get_personality() == personality01 );
110 my_vector vec07(vec01_ref.begin(), vec01_ref.end(), alloc02);
111 size01 = vec07.size();
112 personality01 = vec07.get_allocator().get_personality();
113 my_vector vec08(vec03_ref.begin(), vec03_ref.end(), alloc01);
114 size02 = vec08.size();
115 personality02 = vec08.get_allocator().get_personality();
117 vec07.swap(vec08);
118 VERIFY( vec07.size() == size02 );
119 VERIFY( equal(vec07.begin(), vec07.end(), vec03_ref.begin()) );
120 VERIFY( vec08.size() == size01 );
121 VERIFY( equal(vec08.begin(), vec08.end(), vec01_ref.begin()) );
122 VERIFY( vec07.get_allocator().get_personality() == personality02 );
123 VERIFY( vec08.get_allocator().get_personality() == personality01 );
125 my_vector vec09(vec03_ref.begin(), vec03_ref.end(), alloc01);
126 size01 = vec09.size();
127 personality01 = vec09.get_allocator().get_personality();
128 my_vector vec10(vec04_ref.begin(), vec04_ref.end(), alloc02);
129 size02 = vec10.size();
130 personality02 = vec10.get_allocator().get_personality();
132 vec09.swap(vec10);
133 VERIFY( vec09.size() == size02 );
134 VERIFY( equal(vec09.begin(), vec09.end(), vec04_ref.begin()) );
135 VERIFY( vec10.size() == size01 );
136 VERIFY( equal(vec10.begin(), vec10.end(), vec03_ref.begin()) );
137 VERIFY( vec09.get_allocator().get_personality() == personality02 );
138 VERIFY( vec10.get_allocator().get_personality() == personality01 );
140 my_vector vec11(vec04_ref.begin(), vec04_ref.end(), alloc02);
141 size01 = vec11.size();
142 personality01 = vec11.get_allocator().get_personality();
143 my_vector vec12(vec01_ref.begin(), vec01_ref.end(), alloc01);
144 size02 = vec12.size();
145 personality02 = vec12.get_allocator().get_personality();
147 vec11.swap(vec12);
148 VERIFY( vec11.size() == size02 );
149 VERIFY( equal(vec11.begin(), vec11.end(), vec01_ref.begin()) );
150 VERIFY( vec12.size() == size01 );
151 VERIFY( equal(vec12.begin(), vec12.end(), vec04_ref.begin()) );
152 VERIFY( vec11.get_allocator().get_personality() == personality02 );
153 VERIFY( vec12.get_allocator().get_personality() == personality01 );
155 my_vector vec13(vec03_ref.begin(), vec03_ref.end(), alloc01);
156 size01 = vec13.size();
157 personality01 = vec13.get_allocator().get_personality();
158 my_vector vec14(vec03_ref.begin(), vec03_ref.end(), alloc02);
159 size02 = vec14.size();
160 personality02 = vec14.get_allocator().get_personality();
162 vec13.swap(vec14);
163 VERIFY( vec13.size() == size02 );
164 VERIFY( equal(vec13.begin(), vec13.end(), vec03_ref.begin()) );
165 VERIFY( vec14.size() == size01 );
166 VERIFY( equal(vec14.begin(), vec14.end(), vec03_ref.begin()) );
167 VERIFY( vec13.get_allocator().get_personality() == personality02 );
168 VERIFY( vec14.get_allocator().get_personality() == personality01 );
171 int main()
173 test01();
174 return 0;