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 map 13 14 // pair<iterator,iterator> equal_range(const key_type& k); 15 // pair<const_iterator,const_iterator> equal_range(const key_type& k) const; 16 17 #include <map> 18 #include <cassert> 19 20 #include "min_allocator.h" 21 #include "private_constructor.hpp" 22 #include "is_transparent.h" 23 24 int main() 25 { 26 { 27 typedef std::pair<const int, double> V; 28 typedef std::map<int, double> M; 29 { 30 typedef std::pair<M::iterator, M::iterator> R; 31 V ar[] = 32 { 33 V(5, 5), 34 V(7, 6), 35 V(9, 7), 36 V(11, 8), 37 V(13, 9), 38 V(15, 10), 39 V(17, 11), 40 V(19, 12) 41 }; 42 M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 43 R r = m.equal_range(5); 44 assert(r.first == next(m.begin(), 0)); 45 assert(r.second == next(m.begin(), 1)); 46 r = m.equal_range(7); 47 assert(r.first == next(m.begin(), 1)); 48 assert(r.second == next(m.begin(), 2)); 49 r = m.equal_range(9); 50 assert(r.first == next(m.begin(), 2)); 51 assert(r.second == next(m.begin(), 3)); 52 r = m.equal_range(11); 53 assert(r.first == next(m.begin(), 3)); 54 assert(r.second == next(m.begin(), 4)); 55 r = m.equal_range(13); 56 assert(r.first == next(m.begin(), 4)); 57 assert(r.second == next(m.begin(), 5)); 58 r = m.equal_range(15); 59 assert(r.first == next(m.begin(), 5)); 60 assert(r.second == next(m.begin(), 6)); 61 r = m.equal_range(17); 62 assert(r.first == next(m.begin(), 6)); 63 assert(r.second == next(m.begin(), 7)); 64 r = m.equal_range(19); 65 assert(r.first == next(m.begin(), 7)); 66 assert(r.second == next(m.begin(), 8)); 67 r = m.equal_range(4); 68 assert(r.first == next(m.begin(), 0)); 69 assert(r.second == next(m.begin(), 0)); 70 r = m.equal_range(6); 71 assert(r.first == next(m.begin(), 1)); 72 assert(r.second == next(m.begin(), 1)); 73 r = m.equal_range(8); 74 assert(r.first == next(m.begin(), 2)); 75 assert(r.second == next(m.begin(), 2)); 76 r = m.equal_range(10); 77 assert(r.first == next(m.begin(), 3)); 78 assert(r.second == next(m.begin(), 3)); 79 r = m.equal_range(12); 80 assert(r.first == next(m.begin(), 4)); 81 assert(r.second == next(m.begin(), 4)); 82 r = m.equal_range(14); 83 assert(r.first == next(m.begin(), 5)); 84 assert(r.second == next(m.begin(), 5)); 85 r = m.equal_range(16); 86 assert(r.first == next(m.begin(), 6)); 87 assert(r.second == next(m.begin(), 6)); 88 r = m.equal_range(18); 89 assert(r.first == next(m.begin(), 7)); 90 assert(r.second == next(m.begin(), 7)); 91 r = m.equal_range(20); 92 assert(r.first == next(m.begin(), 8)); 93 assert(r.second == next(m.begin(), 8)); 94 } 95 { 96 typedef std::pair<M::const_iterator, M::const_iterator> R; 97 V ar[] = 98 { 99 V(5, 5), 100 V(7, 6), 101 V(9, 7), 102 V(11, 8), 103 V(13, 9), 104 V(15, 10), 105 V(17, 11), 106 V(19, 12) 107 }; 108 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 109 R r = m.equal_range(5); 110 assert(r.first == next(m.begin(), 0)); 111 assert(r.second == next(m.begin(), 1)); 112 r = m.equal_range(7); 113 assert(r.first == next(m.begin(), 1)); 114 assert(r.second == next(m.begin(), 2)); 115 r = m.equal_range(9); 116 assert(r.first == next(m.begin(), 2)); 117 assert(r.second == next(m.begin(), 3)); 118 r = m.equal_range(11); 119 assert(r.first == next(m.begin(), 3)); 120 assert(r.second == next(m.begin(), 4)); 121 r = m.equal_range(13); 122 assert(r.first == next(m.begin(), 4)); 123 assert(r.second == next(m.begin(), 5)); 124 r = m.equal_range(15); 125 assert(r.first == next(m.begin(), 5)); 126 assert(r.second == next(m.begin(), 6)); 127 r = m.equal_range(17); 128 assert(r.first == next(m.begin(), 6)); 129 assert(r.second == next(m.begin(), 7)); 130 r = m.equal_range(19); 131 assert(r.first == next(m.begin(), 7)); 132 assert(r.second == next(m.begin(), 8)); 133 r = m.equal_range(4); 134 assert(r.first == next(m.begin(), 0)); 135 assert(r.second == next(m.begin(), 0)); 136 r = m.equal_range(6); 137 assert(r.first == next(m.begin(), 1)); 138 assert(r.second == next(m.begin(), 1)); 139 r = m.equal_range(8); 140 assert(r.first == next(m.begin(), 2)); 141 assert(r.second == next(m.begin(), 2)); 142 r = m.equal_range(10); 143 assert(r.first == next(m.begin(), 3)); 144 assert(r.second == next(m.begin(), 3)); 145 r = m.equal_range(12); 146 assert(r.first == next(m.begin(), 4)); 147 assert(r.second == next(m.begin(), 4)); 148 r = m.equal_range(14); 149 assert(r.first == next(m.begin(), 5)); 150 assert(r.second == next(m.begin(), 5)); 151 r = m.equal_range(16); 152 assert(r.first == next(m.begin(), 6)); 153 assert(r.second == next(m.begin(), 6)); 154 r = m.equal_range(18); 155 assert(r.first == next(m.begin(), 7)); 156 assert(r.second == next(m.begin(), 7)); 157 r = m.equal_range(20); 158 assert(r.first == next(m.begin(), 8)); 159 assert(r.second == next(m.begin(), 8)); 160 } 161 } 162 #if __cplusplus >= 201103L 163 { 164 typedef std::pair<const int, double> V; 165 typedef std::map<int, double, std::less<int>, min_allocator<V>> M; 166 { 167 typedef std::pair<M::iterator, M::iterator> R; 168 V ar[] = 169 { 170 V(5, 5), 171 V(7, 6), 172 V(9, 7), 173 V(11, 8), 174 V(13, 9), 175 V(15, 10), 176 V(17, 11), 177 V(19, 12) 178 }; 179 M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 180 R r = m.equal_range(5); 181 assert(r.first == next(m.begin(), 0)); 182 assert(r.second == next(m.begin(), 1)); 183 r = m.equal_range(7); 184 assert(r.first == next(m.begin(), 1)); 185 assert(r.second == next(m.begin(), 2)); 186 r = m.equal_range(9); 187 assert(r.first == next(m.begin(), 2)); 188 assert(r.second == next(m.begin(), 3)); 189 r = m.equal_range(11); 190 assert(r.first == next(m.begin(), 3)); 191 assert(r.second == next(m.begin(), 4)); 192 r = m.equal_range(13); 193 assert(r.first == next(m.begin(), 4)); 194 assert(r.second == next(m.begin(), 5)); 195 r = m.equal_range(15); 196 assert(r.first == next(m.begin(), 5)); 197 assert(r.second == next(m.begin(), 6)); 198 r = m.equal_range(17); 199 assert(r.first == next(m.begin(), 6)); 200 assert(r.second == next(m.begin(), 7)); 201 r = m.equal_range(19); 202 assert(r.first == next(m.begin(), 7)); 203 assert(r.second == next(m.begin(), 8)); 204 r = m.equal_range(4); 205 assert(r.first == next(m.begin(), 0)); 206 assert(r.second == next(m.begin(), 0)); 207 r = m.equal_range(6); 208 assert(r.first == next(m.begin(), 1)); 209 assert(r.second == next(m.begin(), 1)); 210 r = m.equal_range(8); 211 assert(r.first == next(m.begin(), 2)); 212 assert(r.second == next(m.begin(), 2)); 213 r = m.equal_range(10); 214 assert(r.first == next(m.begin(), 3)); 215 assert(r.second == next(m.begin(), 3)); 216 r = m.equal_range(12); 217 assert(r.first == next(m.begin(), 4)); 218 assert(r.second == next(m.begin(), 4)); 219 r = m.equal_range(14); 220 assert(r.first == next(m.begin(), 5)); 221 assert(r.second == next(m.begin(), 5)); 222 r = m.equal_range(16); 223 assert(r.first == next(m.begin(), 6)); 224 assert(r.second == next(m.begin(), 6)); 225 r = m.equal_range(18); 226 assert(r.first == next(m.begin(), 7)); 227 assert(r.second == next(m.begin(), 7)); 228 r = m.equal_range(20); 229 assert(r.first == next(m.begin(), 8)); 230 assert(r.second == next(m.begin(), 8)); 231 } 232 { 233 typedef std::pair<M::const_iterator, M::const_iterator> R; 234 V ar[] = 235 { 236 V(5, 5), 237 V(7, 6), 238 V(9, 7), 239 V(11, 8), 240 V(13, 9), 241 V(15, 10), 242 V(17, 11), 243 V(19, 12) 244 }; 245 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 246 R r = m.equal_range(5); 247 assert(r.first == next(m.begin(), 0)); 248 assert(r.second == next(m.begin(), 1)); 249 r = m.equal_range(7); 250 assert(r.first == next(m.begin(), 1)); 251 assert(r.second == next(m.begin(), 2)); 252 r = m.equal_range(9); 253 assert(r.first == next(m.begin(), 2)); 254 assert(r.second == next(m.begin(), 3)); 255 r = m.equal_range(11); 256 assert(r.first == next(m.begin(), 3)); 257 assert(r.second == next(m.begin(), 4)); 258 r = m.equal_range(13); 259 assert(r.first == next(m.begin(), 4)); 260 assert(r.second == next(m.begin(), 5)); 261 r = m.equal_range(15); 262 assert(r.first == next(m.begin(), 5)); 263 assert(r.second == next(m.begin(), 6)); 264 r = m.equal_range(17); 265 assert(r.first == next(m.begin(), 6)); 266 assert(r.second == next(m.begin(), 7)); 267 r = m.equal_range(19); 268 assert(r.first == next(m.begin(), 7)); 269 assert(r.second == next(m.begin(), 8)); 270 r = m.equal_range(4); 271 assert(r.first == next(m.begin(), 0)); 272 assert(r.second == next(m.begin(), 0)); 273 r = m.equal_range(6); 274 assert(r.first == next(m.begin(), 1)); 275 assert(r.second == next(m.begin(), 1)); 276 r = m.equal_range(8); 277 assert(r.first == next(m.begin(), 2)); 278 assert(r.second == next(m.begin(), 2)); 279 r = m.equal_range(10); 280 assert(r.first == next(m.begin(), 3)); 281 assert(r.second == next(m.begin(), 3)); 282 r = m.equal_range(12); 283 assert(r.first == next(m.begin(), 4)); 284 assert(r.second == next(m.begin(), 4)); 285 r = m.equal_range(14); 286 assert(r.first == next(m.begin(), 5)); 287 assert(r.second == next(m.begin(), 5)); 288 r = m.equal_range(16); 289 assert(r.first == next(m.begin(), 6)); 290 assert(r.second == next(m.begin(), 6)); 291 r = m.equal_range(18); 292 assert(r.first == next(m.begin(), 7)); 293 assert(r.second == next(m.begin(), 7)); 294 r = m.equal_range(20); 295 assert(r.first == next(m.begin(), 8)); 296 assert(r.second == next(m.begin(), 8)); 297 } 298 } 299 #endif 300 #if _LIBCPP_STD_VER > 11 301 { 302 typedef std::pair<const int, double> V; 303 typedef std::map<int, double, std::less<>> M; 304 typedef std::pair<M::iterator, M::iterator> R; 305 306 V ar[] = 307 { 308 V(5, 5), 309 V(7, 6), 310 V(9, 7), 311 V(11, 8), 312 V(13, 9), 313 V(15, 10), 314 V(17, 11), 315 V(19, 12) 316 }; 317 M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 318 R r = m.equal_range(5); 319 assert(r.first == next(m.begin(), 0)); 320 assert(r.second == next(m.begin(), 1)); 321 r = m.equal_range(7); 322 assert(r.first == next(m.begin(), 1)); 323 assert(r.second == next(m.begin(), 2)); 324 r = m.equal_range(9); 325 assert(r.first == next(m.begin(), 2)); 326 assert(r.second == next(m.begin(), 3)); 327 r = m.equal_range(11); 328 assert(r.first == next(m.begin(), 3)); 329 assert(r.second == next(m.begin(), 4)); 330 r = m.equal_range(13); 331 assert(r.first == next(m.begin(), 4)); 332 assert(r.second == next(m.begin(), 5)); 333 r = m.equal_range(15); 334 assert(r.first == next(m.begin(), 5)); 335 assert(r.second == next(m.begin(), 6)); 336 r = m.equal_range(17); 337 assert(r.first == next(m.begin(), 6)); 338 assert(r.second == next(m.begin(), 7)); 339 r = m.equal_range(19); 340 assert(r.first == next(m.begin(), 7)); 341 assert(r.second == next(m.begin(), 8)); 342 r = m.equal_range(4); 343 assert(r.first == next(m.begin(), 0)); 344 assert(r.second == next(m.begin(), 0)); 345 r = m.equal_range(6); 346 assert(r.first == next(m.begin(), 1)); 347 assert(r.second == next(m.begin(), 1)); 348 r = m.equal_range(8); 349 assert(r.first == next(m.begin(), 2)); 350 assert(r.second == next(m.begin(), 2)); 351 r = m.equal_range(10); 352 assert(r.first == next(m.begin(), 3)); 353 assert(r.second == next(m.begin(), 3)); 354 r = m.equal_range(12); 355 assert(r.first == next(m.begin(), 4)); 356 assert(r.second == next(m.begin(), 4)); 357 r = m.equal_range(14); 358 assert(r.first == next(m.begin(), 5)); 359 assert(r.second == next(m.begin(), 5)); 360 r = m.equal_range(16); 361 assert(r.first == next(m.begin(), 6)); 362 assert(r.second == next(m.begin(), 6)); 363 r = m.equal_range(18); 364 assert(r.first == next(m.begin(), 7)); 365 assert(r.second == next(m.begin(), 7)); 366 r = m.equal_range(20); 367 assert(r.first == next(m.begin(), 8)); 368 assert(r.second == next(m.begin(), 8)); 369 370 r = m.equal_range(C2Int(5)); 371 assert(r.first == next(m.begin(), 0)); 372 assert(r.second == next(m.begin(), 1)); 373 r = m.equal_range(C2Int(7)); 374 assert(r.first == next(m.begin(), 1)); 375 assert(r.second == next(m.begin(), 2)); 376 r = m.equal_range(C2Int(9)); 377 assert(r.first == next(m.begin(), 2)); 378 assert(r.second == next(m.begin(), 3)); 379 r = m.equal_range(C2Int(11)); 380 assert(r.first == next(m.begin(), 3)); 381 assert(r.second == next(m.begin(), 4)); 382 r = m.equal_range(C2Int(13)); 383 assert(r.first == next(m.begin(), 4)); 384 assert(r.second == next(m.begin(), 5)); 385 r = m.equal_range(C2Int(15)); 386 assert(r.first == next(m.begin(), 5)); 387 assert(r.second == next(m.begin(), 6)); 388 r = m.equal_range(C2Int(17)); 389 assert(r.first == next(m.begin(), 6)); 390 assert(r.second == next(m.begin(), 7)); 391 r = m.equal_range(C2Int(19)); 392 assert(r.first == next(m.begin(), 7)); 393 assert(r.second == next(m.begin(), 8)); 394 r = m.equal_range(C2Int(4)); 395 assert(r.first == next(m.begin(), 0)); 396 assert(r.second == next(m.begin(), 0)); 397 r = m.equal_range(C2Int(6)); 398 assert(r.first == next(m.begin(), 1)); 399 assert(r.second == next(m.begin(), 1)); 400 r = m.equal_range(C2Int(8)); 401 assert(r.first == next(m.begin(), 2)); 402 assert(r.second == next(m.begin(), 2)); 403 r = m.equal_range(C2Int(10)); 404 assert(r.first == next(m.begin(), 3)); 405 assert(r.second == next(m.begin(), 3)); 406 r = m.equal_range(C2Int(12)); 407 assert(r.first == next(m.begin(), 4)); 408 assert(r.second == next(m.begin(), 4)); 409 r = m.equal_range(C2Int(14)); 410 assert(r.first == next(m.begin(), 5)); 411 assert(r.second == next(m.begin(), 5)); 412 r = m.equal_range(C2Int(16)); 413 assert(r.first == next(m.begin(), 6)); 414 assert(r.second == next(m.begin(), 6)); 415 r = m.equal_range(C2Int(18)); 416 assert(r.first == next(m.begin(), 7)); 417 assert(r.second == next(m.begin(), 7)); 418 r = m.equal_range(C2Int(20)); 419 assert(r.first == next(m.begin(), 8)); 420 assert(r.second == next(m.begin(), 8)); 421 } 422 { 423 typedef PrivateConstructor PC; 424 typedef std::map<PC, double, std::less<>> M; 425 typedef std::pair<M::iterator, M::iterator> R; 426 427 M m; 428 m [ PC::make(5) ] = 5; 429 m [ PC::make(7) ] = 6; 430 m [ PC::make(9) ] = 7; 431 m [ PC::make(11) ] = 8; 432 m [ PC::make(13) ] = 9; 433 m [ PC::make(15) ] = 10; 434 m [ PC::make(17) ] = 11; 435 m [ PC::make(19) ] = 12; 436 437 R r = m.equal_range(5); 438 assert(r.first == next(m.begin(), 0)); 439 assert(r.second == next(m.begin(), 1)); 440 r = m.equal_range(7); 441 assert(r.first == next(m.begin(), 1)); 442 assert(r.second == next(m.begin(), 2)); 443 r = m.equal_range(9); 444 assert(r.first == next(m.begin(), 2)); 445 assert(r.second == next(m.begin(), 3)); 446 r = m.equal_range(11); 447 assert(r.first == next(m.begin(), 3)); 448 assert(r.second == next(m.begin(), 4)); 449 r = m.equal_range(13); 450 assert(r.first == next(m.begin(), 4)); 451 assert(r.second == next(m.begin(), 5)); 452 r = m.equal_range(15); 453 assert(r.first == next(m.begin(), 5)); 454 assert(r.second == next(m.begin(), 6)); 455 r = m.equal_range(17); 456 assert(r.first == next(m.begin(), 6)); 457 assert(r.second == next(m.begin(), 7)); 458 r = m.equal_range(19); 459 assert(r.first == next(m.begin(), 7)); 460 assert(r.second == next(m.begin(), 8)); 461 r = m.equal_range(4); 462 assert(r.first == next(m.begin(), 0)); 463 assert(r.second == next(m.begin(), 0)); 464 r = m.equal_range(6); 465 assert(r.first == next(m.begin(), 1)); 466 assert(r.second == next(m.begin(), 1)); 467 r = m.equal_range(8); 468 assert(r.first == next(m.begin(), 2)); 469 assert(r.second == next(m.begin(), 2)); 470 r = m.equal_range(10); 471 assert(r.first == next(m.begin(), 3)); 472 assert(r.second == next(m.begin(), 3)); 473 r = m.equal_range(12); 474 assert(r.first == next(m.begin(), 4)); 475 assert(r.second == next(m.begin(), 4)); 476 r = m.equal_range(14); 477 assert(r.first == next(m.begin(), 5)); 478 assert(r.second == next(m.begin(), 5)); 479 r = m.equal_range(16); 480 assert(r.first == next(m.begin(), 6)); 481 assert(r.second == next(m.begin(), 6)); 482 r = m.equal_range(18); 483 assert(r.first == next(m.begin(), 7)); 484 assert(r.second == next(m.begin(), 7)); 485 r = m.equal_range(20); 486 assert(r.first == next(m.begin(), 8)); 487 assert(r.second == next(m.begin(), 8)); 488 } 489 #endif 490 } 491