]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc
1 // 2005-12-20 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/>.
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // uneq_allocator, two different personalities.
32 typedef pair
<const char, int> my_pair
;
33 typedef __gnu_test::uneq_allocator
<my_pair
> my_alloc
;
34 typedef map
<char, int, less
<char>, my_alloc
> my_map
;
36 const char title01
[] = "Rivers of sand";
37 const char title02
[] = "Concret PH";
38 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
39 const char title04
[] = "never as tired as when i'm waking up";
41 const size_t N1
= sizeof(title01
);
42 const size_t N2
= sizeof(title02
);
43 const size_t N3
= sizeof(title03
);
44 const size_t N4
= sizeof(title04
);
46 map
<char, int> map01_ref
;
47 for (size_t i
= 0; i
< N1
; ++i
)
48 map01_ref
.insert(my_pair(title01
[i
], i
));
49 map
<char, int> map02_ref
;
50 for (size_t i
= 0; i
< N2
; ++i
)
51 map02_ref
.insert(my_pair(title02
[i
], i
));
52 map
<char, int> map03_ref
;
53 for (size_t i
= 0; i
< N3
; ++i
)
54 map03_ref
.insert(my_pair(title03
[i
], i
));
55 map
<char, int> map04_ref
;
56 for (size_t i
= 0; i
< N4
; ++i
)
57 map04_ref
.insert(my_pair(title04
[i
], i
));
59 my_map::size_type size01
, size02
;
61 my_alloc
alloc01(1), alloc02(2);
62 int personality01
, personality02
;
64 my_map
map01(less
<char>(), alloc01
);
65 size01
= map01
.size();
66 personality01
= map01
.get_allocator().get_personality();
67 my_map
map02(less
<char>(), alloc02
);
68 size02
= map02
.size();
69 personality02
= map02
.get_allocator().get_personality();
72 VERIFY( map01
.size() == size02
);
73 VERIFY( map01
.empty() );
74 VERIFY( map02
.size() == size01
);
75 VERIFY( map02
.empty() );
76 VERIFY( map01
.get_allocator().get_personality() == personality02
);
77 VERIFY( map02
.get_allocator().get_personality() == personality01
);
79 my_map
map03(less
<char>(), alloc02
);
80 size01
= map03
.size();
81 personality01
= map03
.get_allocator().get_personality();
82 my_map
map04(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc01
);
83 size02
= map04
.size();
84 personality02
= map04
.get_allocator().get_personality();
87 VERIFY( map03
.size() == size02
);
88 VERIFY( equal(map03
.begin(), map03
.end(), map02_ref
.begin()) );
89 VERIFY( map04
.size() == size01
);
90 VERIFY( map04
.empty() );
91 VERIFY( map03
.get_allocator().get_personality() == personality02
);
92 VERIFY( map04
.get_allocator().get_personality() == personality01
);
94 my_map
map05(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
95 size01
= map05
.size();
96 personality01
= map05
.get_allocator().get_personality();
97 my_map
map06(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc02
);
98 size02
= map06
.size();
99 personality02
= map06
.get_allocator().get_personality();
102 VERIFY( map05
.size() == size02
);
103 VERIFY( equal(map05
.begin(), map05
.end(), map02_ref
.begin()) );
104 VERIFY( map06
.size() == size01
);
105 VERIFY( equal(map06
.begin(), map06
.end(), map01_ref
.begin()) );
106 VERIFY( map05
.get_allocator().get_personality() == personality02
);
107 VERIFY( map06
.get_allocator().get_personality() == personality01
);
109 my_map
map07(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc02
);
110 size01
= map07
.size();
111 personality01
= map07
.get_allocator().get_personality();
112 my_map
map08(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
113 size02
= map08
.size();
114 personality02
= map08
.get_allocator().get_personality();
117 VERIFY( map07
.size() == size02
);
118 VERIFY( equal(map07
.begin(), map07
.end(), map03_ref
.begin()) );
119 VERIFY( map08
.size() == size01
);
120 VERIFY( equal(map08
.begin(), map08
.end(), map01_ref
.begin()) );
121 VERIFY( map07
.get_allocator().get_personality() == personality02
);
122 VERIFY( map08
.get_allocator().get_personality() == personality01
);
124 my_map
map09(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
125 size01
= map09
.size();
126 personality01
= map09
.get_allocator().get_personality();
127 my_map
map10(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc02
);
128 size02
= map10
.size();
129 personality02
= map10
.get_allocator().get_personality();
132 VERIFY( map09
.size() == size02
);
133 VERIFY( equal(map09
.begin(), map09
.end(), map04_ref
.begin()) );
134 VERIFY( map10
.size() == size01
);
135 VERIFY( equal(map10
.begin(), map10
.end(), map03_ref
.begin()) );
136 VERIFY( map09
.get_allocator().get_personality() == personality02
);
137 VERIFY( map10
.get_allocator().get_personality() == personality01
);
139 my_map
map11(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc02
);
140 size01
= map11
.size();
141 personality01
= map11
.get_allocator().get_personality();
142 my_map
map12(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
143 size02
= map12
.size();
144 personality02
= map12
.get_allocator().get_personality();
147 VERIFY( map11
.size() == size02
);
148 VERIFY( equal(map11
.begin(), map11
.end(), map01_ref
.begin()) );
149 VERIFY( map12
.size() == size01
);
150 VERIFY( equal(map12
.begin(), map12
.end(), map04_ref
.begin()) );
151 VERIFY( map11
.get_allocator().get_personality() == personality02
);
152 VERIFY( map12
.get_allocator().get_personality() == personality01
);
154 my_map
map13(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
155 size01
= map13
.size();
156 personality01
= map13
.get_allocator().get_personality();
157 my_map
map14(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc02
);
158 size02
= map14
.size();
159 personality02
= map14
.get_allocator().get_personality();
162 VERIFY( map13
.size() == size02
);
163 VERIFY( equal(map13
.begin(), map13
.end(), map03_ref
.begin()) );
164 VERIFY( map14
.size() == size01
);
165 VERIFY( equal(map14
.begin(), map14
.end(), map03_ref
.begin()) );
166 VERIFY( map13
.get_allocator().get_personality() == personality02
);
167 VERIFY( map14
.get_allocator().get_personality() == personality01
);