1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++98, c++03 10 11 // <map> 12 13 // class multimap 14 15 // multimap(multimap&& m, const allocator_type& a); 16 17 #include <map> 18 #include <cassert> 19 20 #include "MoveOnly.h" 21 #include "../../../test_compare.h" 22 #include "test_allocator.h" 23 #include "min_allocator.h" 24 #include "Counter.h" 25 26 int main() 27 { 28 { 29 typedef std::pair<MoveOnly, MoveOnly> V; 30 typedef std::pair<const MoveOnly, MoveOnly> VC; 31 typedef test_compare<std::less<MoveOnly> > C; 32 typedef test_allocator<VC> A; 33 typedef std::multimap<MoveOnly, MoveOnly, C, A> M; 34 typedef std::move_iterator<V*> I; 35 V a1[] = 36 { 37 V(1, 1), 38 V(1, 2), 39 V(1, 3), 40 V(2, 1), 41 V(2, 2), 42 V(2, 3), 43 V(3, 1), 44 V(3, 2), 45 V(3, 3) 46 }; 47 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 48 V a2[] = 49 { 50 V(1, 1), 51 V(1, 2), 52 V(1, 3), 53 V(2, 1), 54 V(2, 2), 55 V(2, 3), 56 V(3, 1), 57 V(3, 2), 58 V(3, 3) 59 }; 60 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 61 M m3(std::move(m1), A(7)); 62 assert(m3 == m2); 63 assert(m3.get_allocator() == A(7)); 64 assert(m3.key_comp() == C(5)); 65 assert(m1.empty()); 66 } 67 { 68 typedef std::pair<MoveOnly, MoveOnly> V; 69 typedef std::pair<const MoveOnly, MoveOnly> VC; 70 typedef test_compare<std::less<MoveOnly> > C; 71 typedef test_allocator<VC> A; 72 typedef std::multimap<MoveOnly, MoveOnly, C, A> M; 73 typedef std::move_iterator<V*> I; 74 V a1[] = 75 { 76 V(1, 1), 77 V(1, 2), 78 V(1, 3), 79 V(2, 1), 80 V(2, 2), 81 V(2, 3), 82 V(3, 1), 83 V(3, 2), 84 V(3, 3) 85 }; 86 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 87 V a2[] = 88 { 89 V(1, 1), 90 V(1, 2), 91 V(1, 3), 92 V(2, 1), 93 V(2, 2), 94 V(2, 3), 95 V(3, 1), 96 V(3, 2), 97 V(3, 3) 98 }; 99 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 100 M m3(std::move(m1), A(5)); 101 assert(m3 == m2); 102 assert(m3.get_allocator() == A(5)); 103 assert(m3.key_comp() == C(5)); 104 assert(m1.empty()); 105 } 106 { 107 typedef std::pair<MoveOnly, MoveOnly> V; 108 typedef std::pair<const MoveOnly, MoveOnly> VC; 109 typedef test_compare<std::less<MoveOnly> > C; 110 typedef other_allocator<VC> A; 111 typedef std::multimap<MoveOnly, MoveOnly, C, A> M; 112 typedef std::move_iterator<V*> I; 113 V a1[] = 114 { 115 V(1, 1), 116 V(1, 2), 117 V(1, 3), 118 V(2, 1), 119 V(2, 2), 120 V(2, 3), 121 V(3, 1), 122 V(3, 2), 123 V(3, 3) 124 }; 125 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 126 V a2[] = 127 { 128 V(1, 1), 129 V(1, 2), 130 V(1, 3), 131 V(2, 1), 132 V(2, 2), 133 V(2, 3), 134 V(3, 1), 135 V(3, 2), 136 V(3, 3) 137 }; 138 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 139 M m3(std::move(m1), A(5)); 140 assert(m3 == m2); 141 assert(m3.get_allocator() == A(5)); 142 assert(m3.key_comp() == C(5)); 143 assert(m1.empty()); 144 } 145 { 146 typedef Counter<int> T; 147 typedef std::pair<int, T> V; 148 typedef std::pair<const int, T> VC; 149 typedef test_allocator<VC> A; 150 typedef std::less<int> C; 151 typedef std::multimap<const int, T, C, A> M; 152 typedef V* I; 153 Counter_base::gConstructed = 0; 154 { 155 V a1[] = 156 { 157 V(1, 1), 158 V(1, 2), 159 V(1, 3), 160 V(2, 1), 161 V(2, 2), 162 V(2, 3), 163 V(3, 1), 164 V(3, 2), 165 V(3, 3) 166 }; 167 const size_t num = sizeof(a1)/sizeof(a1[0]); 168 assert(Counter_base::gConstructed == num); 169 170 M m1(I(a1), I(a1+num), C(), A()); 171 assert(Counter_base::gConstructed == 2*num); 172 173 M m2(m1); 174 assert(m2 == m1); 175 assert(Counter_base::gConstructed == 3*num); 176 177 M m3(std::move(m1), A()); 178 assert(m3 == m2); 179 assert(m1.empty()); 180 assert(Counter_base::gConstructed == 3*num); 181 182 { 183 M m4(std::move(m2), A(5)); 184 assert(Counter_base::gConstructed == 3*num); 185 assert(m4 == m3); 186 assert(m2.empty()); 187 } 188 assert(Counter_base::gConstructed == 2*num); 189 } 190 assert(Counter_base::gConstructed == 0); 191 } 192 { 193 typedef std::pair<MoveOnly, MoveOnly> V; 194 typedef std::pair<const MoveOnly, MoveOnly> VC; 195 typedef test_compare<std::less<MoveOnly> > C; 196 typedef min_allocator<VC> A; 197 typedef std::multimap<MoveOnly, MoveOnly, C, A> M; 198 typedef std::move_iterator<V*> I; 199 V a1[] = 200 { 201 V(1, 1), 202 V(1, 2), 203 V(1, 3), 204 V(2, 1), 205 V(2, 2), 206 V(2, 3), 207 V(3, 1), 208 V(3, 2), 209 V(3, 3) 210 }; 211 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); 212 V a2[] = 213 { 214 V(1, 1), 215 V(1, 2), 216 V(1, 3), 217 V(2, 1), 218 V(2, 2), 219 V(2, 3), 220 V(3, 1), 221 V(3, 2), 222 V(3, 3) 223 }; 224 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); 225 M m3(std::move(m1), A()); 226 assert(m3 == m2); 227 assert(m3.get_allocator() == A()); 228 assert(m3.key_comp() == C(5)); 229 assert(m1.empty()); 230 } 231 { 232 typedef std::pair<MoveOnly, MoveOnly> V; 233 typedef std::pair<const MoveOnly, MoveOnly> VC; 234 typedef test_compare<std::less<MoveOnly> > C; 235 typedef explicit_allocator<VC> A; 236 typedef std::multimap<MoveOnly, MoveOnly, C, A> M; 237 typedef std::move_iterator<V*> I; 238 V a1[] = 239 { 240 V(1, 1), 241 V(1, 2), 242 V(1, 3), 243 V(2, 1), 244 V(2, 2), 245 V(2, 3), 246 V(3, 1), 247 V(3, 2), 248 V(3, 3) 249 }; 250 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A{}); 251 V a2[] = 252 { 253 V(1, 1), 254 V(1, 2), 255 V(1, 3), 256 V(2, 1), 257 V(2, 2), 258 V(2, 3), 259 V(3, 1), 260 V(3, 2), 261 V(3, 3) 262 }; 263 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A{}); 264 M m3(std::move(m1), A{}); 265 assert(m3 == m2); 266 assert(m3.get_allocator() == A{}); 267 assert(m3.key_comp() == C(5)); 268 assert(m1.empty()); 269 } 270 } 271