1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <map> 11 12 // class multimap 13 14 // template <class Key, class T, class Compare, class Allocator> 15 // void 16 // swap(multimap<Key, T, Compare, Allocator>& x, multimap<Key, T, Compare, Allocator>& y); 17 18 #include <map> 19 #include <cassert> 20 #include "test_allocator.h" 21 #include "../../../test_compare.h" 22 #include "min_allocator.h" 23 24 int main() 25 { 26 typedef std::pair<const int, double> V; 27 { 28 typedef std::multimap<int, double> M; 29 { 30 M m1; 31 M m2; 32 M m1_save = m1; 33 M m2_save = m2; 34 swap(m1, m2); 35 assert(m1 == m2_save); 36 assert(m2 == m1_save); 37 } 38 { 39 V ar2[] = 40 { 41 V(5, 5), 42 V(6, 6), 43 V(7, 7), 44 V(8, 8), 45 V(9, 9), 46 V(10, 10), 47 V(11, 11), 48 V(12, 12) 49 }; 50 M m1; 51 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 52 M m1_save = m1; 53 M m2_save = m2; 54 swap(m1, m2); 55 assert(m1 == m2_save); 56 assert(m2 == m1_save); 57 } 58 { 59 V ar1[] = 60 { 61 V(1, 1), 62 V(2, 2), 63 V(3, 3), 64 V(4, 4) 65 }; 66 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 67 M m2; 68 M m1_save = m1; 69 M m2_save = m2; 70 swap(m1, m2); 71 assert(m1 == m2_save); 72 assert(m2 == m1_save); 73 } 74 { 75 V ar1[] = 76 { 77 V(1, 1), 78 V(2, 2), 79 V(3, 3), 80 V(4, 4) 81 }; 82 V ar2[] = 83 { 84 V(5, 5), 85 V(6, 6), 86 V(7, 7), 87 V(8, 8), 88 V(9, 9), 89 V(10, 10), 90 V(11, 11), 91 V(12, 12) 92 }; 93 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 94 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 95 M m1_save = m1; 96 M m2_save = m2; 97 swap(m1, m2); 98 assert(m1 == m2_save); 99 assert(m2 == m1_save); 100 } 101 { 102 typedef test_allocator<V> A; 103 typedef test_compare<std::less<int> > C; 104 typedef std::multimap<int, double, C, A> M; 105 V ar1[] = 106 { 107 V(1, 1), 108 V(2, 2), 109 V(3, 3), 110 V(4, 4) 111 }; 112 V ar2[] = 113 { 114 V(5, 5), 115 V(6, 6), 116 V(7, 7), 117 V(8, 8), 118 V(9, 9), 119 V(10, 10), 120 V(11, 11), 121 V(12, 12) 122 }; 123 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); 124 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); 125 M m1_save = m1; 126 M m2_save = m2; 127 swap(m1, m2); 128 assert(m1 == m2_save); 129 assert(m2 == m1_save); 130 assert(m1.key_comp() == C(2)); 131 assert(m1.get_allocator() == A(1)); 132 assert(m2.key_comp() == C(1)); 133 assert(m2.get_allocator() == A(2)); 134 } 135 { 136 typedef other_allocator<V> A; 137 typedef test_compare<std::less<int> > C; 138 typedef std::multimap<int, double, C, A> M; 139 V ar1[] = 140 { 141 V(1, 1), 142 V(2, 2), 143 V(3, 3), 144 V(4, 4) 145 }; 146 V ar2[] = 147 { 148 V(5, 5), 149 V(6, 6), 150 V(7, 7), 151 V(8, 8), 152 V(9, 9), 153 V(10, 10), 154 V(11, 11), 155 V(12, 12) 156 }; 157 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); 158 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); 159 M m1_save = m1; 160 M m2_save = m2; 161 swap(m1, m2); 162 assert(m1 == m2_save); 163 assert(m2 == m1_save); 164 assert(m1.key_comp() == C(2)); 165 assert(m1.get_allocator() == A(2)); 166 assert(m2.key_comp() == C(1)); 167 assert(m2.get_allocator() == A(1)); 168 } 169 } 170 #if __cplusplus >= 201103L 171 { 172 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; 173 { 174 M m1; 175 M m2; 176 M m1_save = m1; 177 M m2_save = m2; 178 swap(m1, m2); 179 assert(m1 == m2_save); 180 assert(m2 == m1_save); 181 } 182 { 183 V ar2[] = 184 { 185 V(5, 5), 186 V(6, 6), 187 V(7, 7), 188 V(8, 8), 189 V(9, 9), 190 V(10, 10), 191 V(11, 11), 192 V(12, 12) 193 }; 194 M m1; 195 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 196 M m1_save = m1; 197 M m2_save = m2; 198 swap(m1, m2); 199 assert(m1 == m2_save); 200 assert(m2 == m1_save); 201 } 202 { 203 V ar1[] = 204 { 205 V(1, 1), 206 V(2, 2), 207 V(3, 3), 208 V(4, 4) 209 }; 210 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 211 M m2; 212 M m1_save = m1; 213 M m2_save = m2; 214 swap(m1, m2); 215 assert(m1 == m2_save); 216 assert(m2 == m1_save); 217 } 218 { 219 V ar1[] = 220 { 221 V(1, 1), 222 V(2, 2), 223 V(3, 3), 224 V(4, 4) 225 }; 226 V ar2[] = 227 { 228 V(5, 5), 229 V(6, 6), 230 V(7, 7), 231 V(8, 8), 232 V(9, 9), 233 V(10, 10), 234 V(11, 11), 235 V(12, 12) 236 }; 237 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 238 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 239 M m1_save = m1; 240 M m2_save = m2; 241 swap(m1, m2); 242 assert(m1 == m2_save); 243 assert(m2 == m1_save); 244 } 245 { 246 typedef min_allocator<V> A; 247 typedef test_compare<std::less<int> > C; 248 typedef std::multimap<int, double, C, A> M; 249 V ar1[] = 250 { 251 V(1, 1), 252 V(2, 2), 253 V(3, 3), 254 V(4, 4) 255 }; 256 V ar2[] = 257 { 258 V(5, 5), 259 V(6, 6), 260 V(7, 7), 261 V(8, 8), 262 V(9, 9), 263 V(10, 10), 264 V(11, 11), 265 V(12, 12) 266 }; 267 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A()); 268 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A()); 269 M m1_save = m1; 270 M m2_save = m2; 271 swap(m1, m2); 272 assert(m1 == m2_save); 273 assert(m2 == m1_save); 274 assert(m1.key_comp() == C(2)); 275 assert(m1.get_allocator() == A()); 276 assert(m2.key_comp() == C(1)); 277 assert(m2.get_allocator() == A()); 278 } 279 } 280 #endif 281 } 282