]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2019 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.3.2 multimap::swap
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 multimap
<char, int, less
<char>, my_alloc
> my_mmap
;
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 multimap
<char, int> mmap01_ref
;
47 for (size_t i
= 0; i
< N1
; ++i
)
48 mmap01_ref
.insert(my_pair(title01
[i
], i
));
49 multimap
<char, int> mmap02_ref
;
50 for (size_t i
= 0; i
< N2
; ++i
)
51 mmap02_ref
.insert(my_pair(title02
[i
], i
));
52 multimap
<char, int> mmap03_ref
;
53 for (size_t i
= 0; i
< N3
; ++i
)
54 mmap03_ref
.insert(my_pair(title03
[i
], i
));
55 multimap
<char, int> mmap04_ref
;
56 for (size_t i
= 0; i
< N4
; ++i
)
57 mmap04_ref
.insert(my_pair(title04
[i
], i
));
59 my_mmap::size_type size01
, size02
;
61 my_alloc
alloc01(1), alloc02(2);
62 int personality01
, personality02
;
64 my_mmap
mmap01(less
<char>(), alloc01
);
65 size01
= mmap01
.size();
66 personality01
= mmap01
.get_allocator().get_personality();
67 my_mmap
mmap02(less
<char>(), alloc02
);
68 size02
= mmap02
.size();
69 personality02
= mmap02
.get_allocator().get_personality();
72 VERIFY( mmap01
.size() == size02
);
73 VERIFY( mmap01
.empty() );
74 VERIFY( mmap02
.size() == size01
);
75 VERIFY( mmap02
.empty() );
76 VERIFY( mmap01
.get_allocator().get_personality() == personality02
);
77 VERIFY( mmap02
.get_allocator().get_personality() == personality01
);
79 my_mmap
mmap03(less
<char>(), alloc02
);
80 size01
= mmap03
.size();
81 personality01
= mmap03
.get_allocator().get_personality();
82 my_mmap
mmap04(mmap02_ref
.begin(), mmap02_ref
.end(), less
<char>(), alloc01
);
83 size02
= mmap04
.size();
84 personality02
= mmap04
.get_allocator().get_personality();
87 VERIFY( mmap03
.size() == size02
);
88 VERIFY( equal(mmap03
.begin(), mmap03
.end(), mmap02_ref
.begin()) );
89 VERIFY( mmap04
.size() == size01
);
90 VERIFY( mmap04
.empty() );
91 VERIFY( mmap03
.get_allocator().get_personality() == personality02
);
92 VERIFY( mmap04
.get_allocator().get_personality() == personality01
);
94 my_mmap
mmap05(mmap01_ref
.begin(), mmap01_ref
.end(), less
<char>(), alloc01
);
95 size01
= mmap05
.size();
96 personality01
= mmap05
.get_allocator().get_personality();
97 my_mmap
mmap06(mmap02_ref
.begin(), mmap02_ref
.end(), less
<char>(), alloc02
);
98 size02
= mmap06
.size();
99 personality02
= mmap06
.get_allocator().get_personality();
102 VERIFY( mmap05
.size() == size02
);
103 VERIFY( equal(mmap05
.begin(), mmap05
.end(), mmap02_ref
.begin()) );
104 VERIFY( mmap06
.size() == size01
);
105 VERIFY( equal(mmap06
.begin(), mmap06
.end(), mmap01_ref
.begin()) );
106 VERIFY( mmap05
.get_allocator().get_personality() == personality02
);
107 VERIFY( mmap06
.get_allocator().get_personality() == personality01
);
109 my_mmap
mmap07(mmap01_ref
.begin(), mmap01_ref
.end(), less
<char>(), alloc02
);
110 size01
= mmap07
.size();
111 personality01
= mmap07
.get_allocator().get_personality();
112 my_mmap
mmap08(mmap03_ref
.begin(), mmap03_ref
.end(), less
<char>(), alloc01
);
113 size02
= mmap08
.size();
114 personality02
= mmap08
.get_allocator().get_personality();
117 VERIFY( mmap07
.size() == size02
);
118 VERIFY( equal(mmap07
.begin(), mmap07
.end(), mmap03_ref
.begin()) );
119 VERIFY( mmap08
.size() == size01
);
120 VERIFY( equal(mmap08
.begin(), mmap08
.end(), mmap01_ref
.begin()) );
121 VERIFY( mmap07
.get_allocator().get_personality() == personality02
);
122 VERIFY( mmap08
.get_allocator().get_personality() == personality01
);
124 my_mmap
mmap09(mmap03_ref
.begin(), mmap03_ref
.end(), less
<char>(), alloc01
);
125 size01
= mmap09
.size();
126 personality01
= mmap09
.get_allocator().get_personality();
127 my_mmap
mmap10(mmap04_ref
.begin(), mmap04_ref
.end(), less
<char>(), alloc02
);
128 size02
= mmap10
.size();
129 personality02
= mmap10
.get_allocator().get_personality();
132 VERIFY( mmap09
.size() == size02
);
133 VERIFY( equal(mmap09
.begin(), mmap09
.end(), mmap04_ref
.begin()) );
134 VERIFY( mmap10
.size() == size01
);
135 VERIFY( equal(mmap10
.begin(), mmap10
.end(), mmap03_ref
.begin()) );
136 VERIFY( mmap09
.get_allocator().get_personality() == personality02
);
137 VERIFY( mmap10
.get_allocator().get_personality() == personality01
);
139 my_mmap
mmap11(mmap04_ref
.begin(), mmap04_ref
.end(), less
<char>(), alloc02
);
140 size01
= mmap11
.size();
141 personality01
= mmap11
.get_allocator().get_personality();
142 my_mmap
mmap12(mmap01_ref
.begin(), mmap01_ref
.end(), less
<char>(), alloc01
);
143 size02
= mmap12
.size();
144 personality02
= mmap12
.get_allocator().get_personality();
147 VERIFY( mmap11
.size() == size02
);
148 VERIFY( equal(mmap11
.begin(), mmap11
.end(), mmap01_ref
.begin()) );
149 VERIFY( mmap12
.size() == size01
);
150 VERIFY( equal(mmap12
.begin(), mmap12
.end(), mmap04_ref
.begin()) );
151 VERIFY( mmap11
.get_allocator().get_personality() == personality02
);
152 VERIFY( mmap12
.get_allocator().get_personality() == personality01
);
154 my_mmap
mmap13(mmap03_ref
.begin(), mmap03_ref
.end(), less
<char>(), alloc01
);
155 size01
= mmap13
.size();
156 personality01
= mmap13
.get_allocator().get_personality();
157 my_mmap
mmap14(mmap03_ref
.begin(), mmap03_ref
.end(), less
<char>(), alloc02
);
158 size02
= mmap14
.size();
159 personality02
= mmap14
.get_allocator().get_personality();
162 VERIFY( mmap13
.size() == size02
);
163 VERIFY( equal(mmap13
.begin(), mmap13
.end(), mmap03_ref
.begin()) );
164 VERIFY( mmap14
.size() == size01
);
165 VERIFY( equal(mmap14
.begin(), mmap14
.end(), mmap03_ref
.begin()) );
166 VERIFY( mmap13
.get_allocator().get_personality() == personality02
);
167 VERIFY( mmap14
.get_allocator().get_personality() == personality01
);