Brian Silverman | fad8f55 | 2018-08-04 23:36:19 -0700 | [diff] [blame^] | 1 | ////////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost |
| 4 | // Software License, Version 1.0. (See accompanying file |
| 5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | // |
| 7 | // See http://www.boost.org/libs/container for documentation. |
| 8 | // |
| 9 | ////////////////////////////////////////////////////////////////////////////// |
| 10 | |
| 11 | #include <boost/container/detail/config_begin.hpp> |
| 12 | #include <boost/container/flat_map.hpp> |
| 13 | #include <boost/container/allocator.hpp> |
| 14 | #include <boost/container/detail/flat_tree.hpp> |
| 15 | #include <boost/container/stable_vector.hpp> |
| 16 | #include <boost/container/small_vector.hpp> |
| 17 | #include <boost/container/deque.hpp> |
| 18 | #include <boost/container/static_vector.hpp> |
| 19 | #include <boost/container/detail/container_or_allocator_rebind.hpp> |
| 20 | |
| 21 | #include "print_container.hpp" |
| 22 | #include "dummy_test_allocator.hpp" |
| 23 | #include "movable_int.hpp" |
| 24 | #include "map_test.hpp" |
| 25 | #include "propagate_allocator_test.hpp" |
| 26 | #include "container_common_tests.hpp" |
| 27 | #include "emplace_test.hpp" |
| 28 | #include "../../intrusive/test/iterator_test.hpp" |
| 29 | |
| 30 | #include <map> |
| 31 | |
| 32 | |
| 33 | using namespace boost::container; |
| 34 | |
| 35 | namespace boost { |
| 36 | namespace container { |
| 37 | |
| 38 | //Explicit instantiation to detect compilation errors |
| 39 | |
| 40 | //flat_map |
| 41 | typedef std::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> test_pair_t; |
| 42 | |
| 43 | template class flat_map |
| 44 | < test::movable_and_copyable_int |
| 45 | , test::movable_and_copyable_int |
| 46 | , std::less<test::movable_and_copyable_int> |
| 47 | , test::simple_allocator< test_pair_t > |
| 48 | >; |
| 49 | |
| 50 | template class flat_map |
| 51 | < test::movable_and_copyable_int |
| 52 | , test::movable_and_copyable_int |
| 53 | , std::less<test::movable_and_copyable_int> |
| 54 | , small_vector< test_pair_t, 10, std::allocator< test_pair_t > > |
| 55 | >; |
| 56 | |
| 57 | //flat_multimap |
| 58 | template class flat_multimap |
| 59 | < test::movable_and_copyable_int |
| 60 | , test::movable_and_copyable_int |
| 61 | , std::less<test::movable_and_copyable_int> |
| 62 | , stable_vector< test_pair_t, allocator< test_pair_t > > |
| 63 | >; |
| 64 | |
| 65 | template class flat_multimap |
| 66 | < test::movable_and_copyable_int |
| 67 | , test::movable_and_copyable_int |
| 68 | , std::less<test::movable_and_copyable_int> |
| 69 | , deque<test_pair_t, test::simple_allocator< test_pair_t > > |
| 70 | >; |
| 71 | |
| 72 | template class flat_multimap |
| 73 | < test::movable_and_copyable_int |
| 74 | , test::movable_and_copyable_int |
| 75 | , std::less<test::movable_and_copyable_int> |
| 76 | , static_vector<test_pair_t, 10 > |
| 77 | >; |
| 78 | |
| 79 | //As flat container iterators are typedefs for vector::[const_]iterator, |
| 80 | //no need to explicit instantiate them |
| 81 | |
| 82 | }} //boost::container |
| 83 | |
| 84 | #if (__cplusplus > 201103L) |
| 85 | #include <vector> |
| 86 | |
| 87 | namespace boost{ |
| 88 | namespace container{ |
| 89 | |
| 90 | template class flat_map |
| 91 | < test::movable_and_copyable_int |
| 92 | , test::movable_and_copyable_int |
| 93 | , std::less<test::movable_and_copyable_int> |
| 94 | , std::vector<test_pair_t> |
| 95 | >; |
| 96 | |
| 97 | }} //boost::container |
| 98 | |
| 99 | #endif |
| 100 | |
| 101 | class recursive_flat_map |
| 102 | { |
| 103 | public: |
| 104 | recursive_flat_map(const recursive_flat_map &c) |
| 105 | : id_(c.id_), map_(c.map_) |
| 106 | {} |
| 107 | |
| 108 | recursive_flat_map & operator =(const recursive_flat_map &c) |
| 109 | { |
| 110 | id_ = c.id_; |
| 111 | map_= c.map_; |
| 112 | return *this; |
| 113 | } |
| 114 | |
| 115 | int id_; |
| 116 | flat_map<recursive_flat_map, recursive_flat_map> map_; |
| 117 | flat_map<recursive_flat_map, recursive_flat_map>::iterator it_; |
| 118 | flat_map<recursive_flat_map, recursive_flat_map>::const_iterator cit_; |
| 119 | flat_map<recursive_flat_map, recursive_flat_map>::reverse_iterator rit_; |
| 120 | flat_map<recursive_flat_map, recursive_flat_map>::const_reverse_iterator crit_; |
| 121 | |
| 122 | friend bool operator< (const recursive_flat_map &a, const recursive_flat_map &b) |
| 123 | { return a.id_ < b.id_; } |
| 124 | }; |
| 125 | |
| 126 | |
| 127 | class recursive_flat_multimap |
| 128 | { |
| 129 | public: |
| 130 | recursive_flat_multimap(const recursive_flat_multimap &c) |
| 131 | : id_(c.id_), map_(c.map_) |
| 132 | {} |
| 133 | |
| 134 | recursive_flat_multimap & operator =(const recursive_flat_multimap &c) |
| 135 | { |
| 136 | id_ = c.id_; |
| 137 | map_= c.map_; |
| 138 | return *this; |
| 139 | } |
| 140 | int id_; |
| 141 | flat_multimap<recursive_flat_multimap, recursive_flat_multimap> map_; |
| 142 | flat_multimap<recursive_flat_multimap, recursive_flat_multimap>::iterator it_; |
| 143 | flat_multimap<recursive_flat_multimap, recursive_flat_multimap>::const_iterator cit_; |
| 144 | flat_multimap<recursive_flat_multimap, recursive_flat_multimap>::reverse_iterator rit_; |
| 145 | flat_multimap<recursive_flat_multimap, recursive_flat_multimap>::const_reverse_iterator crit_; |
| 146 | |
| 147 | friend bool operator< (const recursive_flat_multimap &a, const recursive_flat_multimap &b) |
| 148 | { return a.id_ < b.id_; } |
| 149 | }; |
| 150 | |
| 151 | template<class C> |
| 152 | void test_move() |
| 153 | { |
| 154 | //Now test move semantics |
| 155 | C original; |
| 156 | C move_ctor(boost::move(original)); |
| 157 | C move_assign; |
| 158 | move_assign = boost::move(move_ctor); |
| 159 | move_assign.swap(original); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | namespace boost{ |
| 164 | namespace container { |
| 165 | namespace test{ |
| 166 | |
| 167 | bool flat_tree_ordered_insertion_test() |
| 168 | { |
| 169 | using namespace boost::container; |
| 170 | const std::size_t NumElements = 100; |
| 171 | |
| 172 | //Ordered insertion multimap |
| 173 | { |
| 174 | std::multimap<int, int> int_mmap; |
| 175 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 176 | int_mmap.insert(std::multimap<int, int>::value_type(static_cast<int>(i), static_cast<int>(i))); |
| 177 | } |
| 178 | //Construction insertion |
| 179 | flat_multimap<int, int> fmmap(ordered_range, int_mmap.begin(), int_mmap.end()); |
| 180 | if(!CheckEqualContainers(int_mmap, fmmap)) |
| 181 | return false; |
| 182 | //Insertion when empty |
| 183 | fmmap.clear(); |
| 184 | fmmap.insert(ordered_range, int_mmap.begin(), int_mmap.end()); |
| 185 | if(!CheckEqualContainers(int_mmap, fmmap)) |
| 186 | return false; |
| 187 | //Re-insertion |
| 188 | fmmap.insert(ordered_range, int_mmap.begin(), int_mmap.end()); |
| 189 | std::multimap<int, int> int_mmap2(int_mmap); |
| 190 | int_mmap2.insert(int_mmap.begin(), int_mmap.end()); |
| 191 | if(!CheckEqualContainers(int_mmap2, fmmap)) |
| 192 | return false; |
| 193 | //Re-re-insertion |
| 194 | fmmap.insert(ordered_range, int_mmap2.begin(), int_mmap2.end()); |
| 195 | std::multimap<int, int> int_mmap4(int_mmap2); |
| 196 | int_mmap4.insert(int_mmap2.begin(), int_mmap2.end()); |
| 197 | if(!CheckEqualContainers(int_mmap4, fmmap)) |
| 198 | return false; |
| 199 | //Re-re-insertion of even |
| 200 | std::multimap<int, int> int_even_mmap; |
| 201 | for(std::size_t i = 0; i < NumElements; i+=2){ |
| 202 | int_mmap.insert(std::multimap<int, int>::value_type(static_cast<int>(i), static_cast<int>(i))); |
| 203 | } |
| 204 | fmmap.insert(ordered_range, int_even_mmap.begin(), int_even_mmap.end()); |
| 205 | int_mmap4.insert(int_even_mmap.begin(), int_even_mmap.end()); |
| 206 | if(!CheckEqualContainers(int_mmap4, fmmap)) |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | //Ordered insertion map |
| 211 | { |
| 212 | std::map<int, int> int_map; |
| 213 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 214 | int_map.insert(std::map<int, int>::value_type(static_cast<int>(i), static_cast<int>(i))); |
| 215 | } |
| 216 | //Construction insertion |
| 217 | flat_map<int, int> fmap(ordered_unique_range, int_map.begin(), int_map.end()); |
| 218 | if(!CheckEqualContainers(int_map, fmap)) |
| 219 | return false; |
| 220 | //Insertion when empty |
| 221 | fmap.clear(); |
| 222 | fmap.insert(ordered_unique_range, int_map.begin(), int_map.end()); |
| 223 | if(!CheckEqualContainers(int_map, fmap)) |
| 224 | return false; |
| 225 | //Re-insertion |
| 226 | fmap.insert(ordered_unique_range, int_map.begin(), int_map.end()); |
| 227 | std::map<int, int> int_map2(int_map); |
| 228 | int_map2.insert(int_map.begin(), int_map.end()); |
| 229 | if(!CheckEqualContainers(int_map2, fmap)) |
| 230 | return false; |
| 231 | //Re-re-insertion |
| 232 | fmap.insert(ordered_unique_range, int_map2.begin(), int_map2.end()); |
| 233 | std::map<int, int> int_map4(int_map2); |
| 234 | int_map4.insert(int_map2.begin(), int_map2.end()); |
| 235 | if(!CheckEqualContainers(int_map4, fmap)) |
| 236 | return false; |
| 237 | //Re-re-insertion of even |
| 238 | std::map<int, int> int_even_map; |
| 239 | for(std::size_t i = 0; i < NumElements; i+=2){ |
| 240 | int_map.insert(std::map<int, int>::value_type(static_cast<int>(i), static_cast<int>(i))); |
| 241 | } |
| 242 | fmap.insert(ordered_unique_range, int_even_map.begin(), int_even_map.end()); |
| 243 | int_map4.insert(int_even_map.begin(), int_even_map.end()); |
| 244 | if(!CheckEqualContainers(int_map4, fmap)) |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | return true; |
| 249 | } |
| 250 | |
| 251 | bool constructor_template_auto_deduction_test() |
| 252 | { |
| 253 | #if __cplusplus >= 201703L |
| 254 | using namespace boost::container; |
| 255 | const std::size_t NumElements = 100; |
| 256 | //Ordered insertion map |
| 257 | { |
| 258 | std::map<int, int> int_map; |
| 259 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 260 | int_map.insert(std::map<int, int>::value_type(static_cast<int>(i), static_cast<int>(i))); |
| 261 | } |
| 262 | //Construction insertion |
| 263 | auto fmap = flat_map(ordered_unique_range, int_map.begin(), int_map.end()); |
| 264 | if(!CheckEqualContainers(int_map, fmap)) |
| 265 | return false; |
| 266 | |
| 267 | std::multimap<int, int> int_mmap; |
| 268 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 269 | int_mmap.insert(std::multimap<int, int>::value_type(static_cast<int>(i), static_cast<int>(i))); |
| 270 | } |
| 271 | //Construction insertion |
| 272 | auto fmmap = flat_multimap(ordered_range, int_mmap.begin(), int_mmap.end()); |
| 273 | if(!CheckEqualContainers(int_mmap, fmmap)) |
| 274 | return false; |
| 275 | } |
| 276 | #endif |
| 277 | |
| 278 | return true; |
| 279 | } |
| 280 | |
| 281 | template< class RandomIt > |
| 282 | void random_shuffle( RandomIt first, RandomIt last ) |
| 283 | { |
| 284 | typedef typename boost::container::iterator_traits<RandomIt>::difference_type difference_type; |
| 285 | difference_type n = last - first; |
| 286 | for (difference_type i = n-1; i > 0; --i) { |
| 287 | difference_type j = std::rand() % (i+1); |
| 288 | if(j != i) { |
| 289 | boost::adl_move_swap(first[i], first[j]); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | bool flat_tree_extract_adopt_test() |
| 295 | { |
| 296 | using namespace boost::container; |
| 297 | const std::size_t NumElements = 100; |
| 298 | |
| 299 | //extract/adopt map |
| 300 | { |
| 301 | //Construction insertion |
| 302 | flat_map<int, int> fmap; |
| 303 | |
| 304 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 305 | fmap.emplace(static_cast<int>(i), -static_cast<int>(i)); |
| 306 | } |
| 307 | |
| 308 | flat_map<int, int> fmap_copy(fmap); |
| 309 | flat_map<int, int>::sequence_type seq(fmap.extract_sequence()); |
| 310 | if(!fmap.empty()) |
| 311 | return false; |
| 312 | if(!CheckEqualContainers(seq, fmap_copy)) |
| 313 | return false; |
| 314 | |
| 315 | seq.insert(seq.end(), fmap_copy.begin(), fmap_copy.end()); |
| 316 | boost::container::test::random_shuffle(seq.begin(), seq.end()); |
| 317 | fmap.adopt_sequence(boost::move(seq)); |
| 318 | if(!CheckEqualContainers(fmap, fmap_copy)) |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | //extract/adopt map, ordered_unique_range |
| 323 | { |
| 324 | //Construction insertion |
| 325 | flat_map<int, int> fmap; |
| 326 | |
| 327 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 328 | fmap.emplace(static_cast<int>(i), -static_cast<int>(i)); |
| 329 | } |
| 330 | |
| 331 | flat_map<int, int> fmap_copy(fmap); |
| 332 | flat_map<int, int>::sequence_type seq(fmap.extract_sequence()); |
| 333 | if(!fmap.empty()) |
| 334 | return false; |
| 335 | if(!CheckEqualContainers(seq, fmap_copy)) |
| 336 | return false; |
| 337 | |
| 338 | fmap.adopt_sequence(ordered_unique_range, boost::move(seq)); |
| 339 | if(!CheckEqualContainers(fmap, fmap_copy)) |
| 340 | return false; |
| 341 | } |
| 342 | |
| 343 | //extract/adopt multimap |
| 344 | { |
| 345 | //Construction insertion |
| 346 | flat_multimap<int, int> fmmap; |
| 347 | |
| 348 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 349 | fmmap.emplace(static_cast<int>(i), -static_cast<int>(i)); |
| 350 | fmmap.emplace(static_cast<int>(i), -static_cast<int>(i)); |
| 351 | } |
| 352 | |
| 353 | flat_multimap<int, int> fmmap_copy(fmmap); |
| 354 | flat_multimap<int, int>::sequence_type seq(fmmap.extract_sequence()); |
| 355 | if(!fmmap.empty()) |
| 356 | return false; |
| 357 | if(!CheckEqualContainers(seq, fmmap_copy)) |
| 358 | return false; |
| 359 | |
| 360 | boost::container::test::random_shuffle(seq.begin(), seq.end()); |
| 361 | fmmap.adopt_sequence(boost::move(seq)); |
| 362 | if(!CheckEqualContainers(fmmap, fmmap_copy)) |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | //extract/adopt multimap, ordered_range |
| 367 | { |
| 368 | //Construction insertion |
| 369 | flat_multimap<int, int> fmmap; |
| 370 | |
| 371 | for(std::size_t i = 0; i != NumElements; ++i){ |
| 372 | fmmap.emplace(static_cast<int>(i), -static_cast<int>(i)); |
| 373 | fmmap.emplace(static_cast<int>(i), -static_cast<int>(i)); |
| 374 | } |
| 375 | |
| 376 | flat_multimap<int, int> fmmap_copy(fmmap); |
| 377 | flat_multimap<int, int>::sequence_type seq(fmmap.extract_sequence()); |
| 378 | if(!fmmap.empty()) |
| 379 | return false; |
| 380 | if(!CheckEqualContainers(seq, fmmap_copy)) |
| 381 | return false; |
| 382 | |
| 383 | fmmap.adopt_sequence(ordered_range, boost::move(seq)); |
| 384 | if(!CheckEqualContainers(fmmap, fmmap_copy)) |
| 385 | return false; |
| 386 | } |
| 387 | |
| 388 | return true; |
| 389 | } |
| 390 | |
| 391 | }}} |
| 392 | |
| 393 | template<class VoidAllocatorOrContainer> |
| 394 | struct GetMapContainer |
| 395 | { |
| 396 | template<class ValueType> |
| 397 | struct apply |
| 398 | { |
| 399 | typedef std::pair<ValueType, ValueType> type_t; |
| 400 | typedef flat_map< ValueType |
| 401 | , ValueType |
| 402 | , std::less<ValueType> |
| 403 | , typename boost::container::dtl::container_or_allocator_rebind<VoidAllocatorOrContainer, type_t>::type |
| 404 | > map_type; |
| 405 | |
| 406 | typedef flat_multimap< ValueType |
| 407 | , ValueType |
| 408 | , std::less<ValueType> |
| 409 | , typename boost::container::dtl::container_or_allocator_rebind<VoidAllocatorOrContainer, type_t>::type |
| 410 | > multimap_type; |
| 411 | }; |
| 412 | }; |
| 413 | |
| 414 | struct boost_container_flat_map; |
| 415 | struct boost_container_flat_multimap; |
| 416 | |
| 417 | namespace boost { namespace container { namespace test { |
| 418 | |
| 419 | template<> |
| 420 | struct alloc_propagate_base<boost_container_flat_map> |
| 421 | { |
| 422 | template <class T, class Allocator> |
| 423 | struct apply |
| 424 | { |
| 425 | typedef typename boost::container::allocator_traits<Allocator>:: |
| 426 | template portable_rebind_alloc<std::pair<T, T> >::type TypeAllocator; |
| 427 | typedef boost::container::flat_map<T, T, std::less<T>, TypeAllocator> type; |
| 428 | }; |
| 429 | }; |
| 430 | |
| 431 | template<> |
| 432 | struct alloc_propagate_base<boost_container_flat_multimap> |
| 433 | { |
| 434 | template <class T, class Allocator> |
| 435 | struct apply |
| 436 | { |
| 437 | typedef typename boost::container::allocator_traits<Allocator>:: |
| 438 | template portable_rebind_alloc<std::pair<T, T> >::type TypeAllocator; |
| 439 | typedef boost::container::flat_multimap<T, T, std::less<T>, TypeAllocator> type; |
| 440 | }; |
| 441 | }; |
| 442 | |
| 443 | template <class Key, class T, class Compare, class Allocator> |
| 444 | struct get_real_stored_allocator<flat_map<Key, T, Compare, Allocator> > |
| 445 | { |
| 446 | typedef typename flat_map<Key, T, Compare, Allocator>::impl_stored_allocator_type type; |
| 447 | }; |
| 448 | |
| 449 | template <class Key, class T, class Compare, class Allocator> |
| 450 | struct get_real_stored_allocator<flat_multimap<Key, T, Compare, Allocator> > |
| 451 | { |
| 452 | typedef typename flat_multimap<Key, T, Compare, Allocator>::impl_stored_allocator_type type; |
| 453 | }; |
| 454 | |
| 455 | bool test_heterogeneous_lookups() |
| 456 | { |
| 457 | typedef flat_map<int, char, less_transparent> map_t; |
| 458 | typedef flat_multimap<int, char, less_transparent> mmap_t; |
| 459 | typedef map_t::value_type value_type; |
| 460 | |
| 461 | map_t map1; |
| 462 | mmap_t mmap1; |
| 463 | |
| 464 | const map_t &cmap1 = map1; |
| 465 | const mmap_t &cmmap1 = mmap1; |
| 466 | |
| 467 | map1.insert_or_assign(1, 'a'); |
| 468 | map1.insert_or_assign(1, 'b'); |
| 469 | map1.insert_or_assign(2, 'c'); |
| 470 | map1.insert_or_assign(2, 'd'); |
| 471 | map1.insert_or_assign(3, 'e'); |
| 472 | |
| 473 | mmap1.insert(value_type(1, 'a')); |
| 474 | mmap1.insert(value_type(1, 'b')); |
| 475 | mmap1.insert(value_type(2, 'c')); |
| 476 | mmap1.insert(value_type(2, 'd')); |
| 477 | mmap1.insert(value_type(3, 'e')); |
| 478 | |
| 479 | const test::non_copymovable_int find_me(2); |
| 480 | |
| 481 | //find |
| 482 | if(map1.find(find_me)->second != 'd') |
| 483 | return false; |
| 484 | if(cmap1.find(find_me)->second != 'd') |
| 485 | return false; |
| 486 | if(mmap1.find(find_me)->second != 'c') |
| 487 | return false; |
| 488 | if(cmmap1.find(find_me)->second != 'c') |
| 489 | return false; |
| 490 | |
| 491 | //count |
| 492 | if(map1.count(find_me) != 1) |
| 493 | return false; |
| 494 | if(cmap1.count(find_me) != 1) |
| 495 | return false; |
| 496 | if(mmap1.count(find_me) != 2) |
| 497 | return false; |
| 498 | if(cmmap1.count(find_me) != 2) |
| 499 | return false; |
| 500 | |
| 501 | //lower_bound |
| 502 | if(map1.lower_bound(find_me)->second != 'd') |
| 503 | return false; |
| 504 | if(cmap1.lower_bound(find_me)->second != 'd') |
| 505 | return false; |
| 506 | if(mmap1.lower_bound(find_me)->second != 'c') |
| 507 | return false; |
| 508 | if(cmmap1.lower_bound(find_me)->second != 'c') |
| 509 | return false; |
| 510 | |
| 511 | //upper_bound |
| 512 | if(map1.upper_bound(find_me)->second != 'e') |
| 513 | return false; |
| 514 | if(cmap1.upper_bound(find_me)->second != 'e') |
| 515 | return false; |
| 516 | if(mmap1.upper_bound(find_me)->second != 'e') |
| 517 | return false; |
| 518 | if(cmmap1.upper_bound(find_me)->second != 'e') |
| 519 | return false; |
| 520 | |
| 521 | //equal_range |
| 522 | if(map1.equal_range(find_me).first->second != 'd') |
| 523 | return false; |
| 524 | if(cmap1.equal_range(find_me).second->second != 'e') |
| 525 | return false; |
| 526 | if(mmap1.equal_range(find_me).first->second != 'c') |
| 527 | return false; |
| 528 | if(cmmap1.equal_range(find_me).second->second != 'e') |
| 529 | return false; |
| 530 | |
| 531 | return true; |
| 532 | } |
| 533 | |
| 534 | }}} //namespace boost::container::test |
| 535 | |
| 536 | template<class VoidAllocatorOrContainer> |
| 537 | int test_map_variants() |
| 538 | { |
| 539 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<int>::map_type MyMap; |
| 540 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<test::movable_int>::map_type MyMoveMap; |
| 541 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<test::movable_and_copyable_int>::map_type MyCopyMoveMap; |
| 542 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<test::copyable_int>::map_type MyCopyMap; |
| 543 | |
| 544 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<int>::multimap_type MyMultiMap; |
| 545 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<test::movable_int>::multimap_type MyMoveMultiMap; |
| 546 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<test::movable_and_copyable_int>::multimap_type MyCopyMoveMultiMap; |
| 547 | typedef typename GetMapContainer<VoidAllocatorOrContainer>::template apply<test::copyable_int>::multimap_type MyCopyMultiMap; |
| 548 | |
| 549 | typedef std::map<int, int> MyStdMap; |
| 550 | typedef std::multimap<int, int> MyStdMultiMap; |
| 551 | |
| 552 | if (0 != test::map_test< |
| 553 | MyMap |
| 554 | ,MyStdMap |
| 555 | ,MyMultiMap |
| 556 | ,MyStdMultiMap>()){ |
| 557 | std::cout << "Error in map_test<MyBoostMap>" << std::endl; |
| 558 | return 1; |
| 559 | } |
| 560 | |
| 561 | if (0 != test::map_test< |
| 562 | MyMoveMap |
| 563 | ,MyStdMap |
| 564 | ,MyMoveMultiMap |
| 565 | ,MyStdMultiMap>()){ |
| 566 | std::cout << "Error in map_test<MyBoostMap>" << std::endl; |
| 567 | return 1; |
| 568 | } |
| 569 | |
| 570 | if (0 != test::map_test< |
| 571 | MyCopyMoveMap |
| 572 | ,MyStdMap |
| 573 | ,MyCopyMoveMultiMap |
| 574 | ,MyStdMultiMap>()){ |
| 575 | std::cout << "Error in map_test<MyBoostMap>" << std::endl; |
| 576 | return 1; |
| 577 | } |
| 578 | |
| 579 | if (0 != test::map_test< |
| 580 | MyCopyMap |
| 581 | ,MyStdMap |
| 582 | ,MyCopyMultiMap |
| 583 | ,MyStdMultiMap>()){ |
| 584 | std::cout << "Error in map_test<MyBoostMap>" << std::endl; |
| 585 | return 1; |
| 586 | } |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | int main() |
| 592 | { |
| 593 | using namespace boost::container::test; |
| 594 | |
| 595 | //Allocator argument container |
| 596 | { |
| 597 | flat_map<int, int> map_((flat_map<int, int>::allocator_type())); |
| 598 | flat_multimap<int, int> multimap_((flat_multimap<int, int>::allocator_type())); |
| 599 | } |
| 600 | //Now test move semantics |
| 601 | { |
| 602 | test_move<flat_map<recursive_flat_map, recursive_flat_map> >(); |
| 603 | test_move<flat_multimap<recursive_flat_multimap, recursive_flat_multimap> >(); |
| 604 | } |
| 605 | //Now test nth/index_of |
| 606 | { |
| 607 | flat_map<int, int> map; |
| 608 | flat_multimap<int, int> mmap; |
| 609 | |
| 610 | map.insert(std::pair<int, int>(0, 0)); |
| 611 | map.insert(std::pair<int, int>(1, 0)); |
| 612 | map.insert(std::pair<int, int>(2, 0)); |
| 613 | mmap.insert(std::pair<int, int>(0, 0)); |
| 614 | mmap.insert(std::pair<int, int>(1, 0)); |
| 615 | mmap.insert(std::pair<int, int>(2, 0)); |
| 616 | if(!boost::container::test::test_nth_index_of(map)) |
| 617 | return 1; |
| 618 | if(!boost::container::test::test_nth_index_of(mmap)) |
| 619 | return 1; |
| 620 | } |
| 621 | |
| 622 | //////////////////////////////////// |
| 623 | // Ordered insertion test |
| 624 | //////////////////////////////////// |
| 625 | if(!flat_tree_ordered_insertion_test()){ |
| 626 | return 1; |
| 627 | } |
| 628 | |
| 629 | //////////////////////////////////// |
| 630 | // Constructor Template Auto Deduction test |
| 631 | //////////////////////////////////// |
| 632 | if(!constructor_template_auto_deduction_test()){ |
| 633 | return 1; |
| 634 | } |
| 635 | |
| 636 | //////////////////////////////////// |
| 637 | // Extract/Adopt test |
| 638 | //////////////////////////////////// |
| 639 | if(!flat_tree_extract_adopt_test()){ |
| 640 | return 1; |
| 641 | } |
| 642 | |
| 643 | if (!boost::container::test::instantiate_constructors<flat_map<int, int>, flat_multimap<int, int> >()) |
| 644 | return 1; |
| 645 | |
| 646 | if (!test_heterogeneous_lookups()) |
| 647 | return 1; |
| 648 | |
| 649 | //////////////////////////////////// |
| 650 | // Testing allocator implementations |
| 651 | //////////////////////////////////// |
| 652 | // std::allocator |
| 653 | if(test_map_variants< std::allocator<void> >()){ |
| 654 | std::cerr << "test_map_variants< std::allocator<void> > failed" << std::endl; |
| 655 | return 1; |
| 656 | } |
| 657 | // boost::container::allocator |
| 658 | if(test_map_variants< allocator<void> >()){ |
| 659 | std::cerr << "test_map_variants< allocator<void> > failed" << std::endl; |
| 660 | return 1; |
| 661 | } |
| 662 | |
| 663 | if(!boost::container::test::test_map_support_for_initialization_list_for<flat_map<int, int> >()) |
| 664 | return 1; |
| 665 | |
| 666 | if (!boost::container::test::test_map_support_for_initialization_list_for<flat_multimap<int, int> >()) |
| 667 | return 1; |
| 668 | |
| 669 | //////////////////////////////////// |
| 670 | // Emplace testing |
| 671 | //////////////////////////////////// |
| 672 | const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR); |
| 673 | |
| 674 | if(!boost::container::test::test_emplace<flat_map<test::EmplaceInt, test::EmplaceInt>, MapOptions>()) |
| 675 | return 1; |
| 676 | if(!boost::container::test::test_emplace<flat_multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>()) |
| 677 | return 1; |
| 678 | |
| 679 | //////////////////////////////////// |
| 680 | // Allocator propagation testing |
| 681 | //////////////////////////////////// |
| 682 | if(!boost::container::test::test_propagate_allocator<boost_container_flat_map>()) |
| 683 | return 1; |
| 684 | |
| 685 | if(!boost::container::test::test_propagate_allocator<boost_container_flat_multimap>()) |
| 686 | return 1; |
| 687 | |
| 688 | //////////////////////////////////// |
| 689 | // Iterator testing |
| 690 | //////////////////////////////////// |
| 691 | { |
| 692 | typedef boost::container::flat_map<int, int> cont_int; |
| 693 | cont_int a; a.insert(cont_int::value_type(0, 9)); a.insert(cont_int::value_type(1, 9)); a.insert(cont_int::value_type(2, 9)); |
| 694 | boost::intrusive::test::test_iterator_random< cont_int >(a); |
| 695 | if(boost::report_errors() != 0) { |
| 696 | return 1; |
| 697 | } |
| 698 | } |
| 699 | { |
| 700 | typedef boost::container::flat_multimap<int, int> cont_int; |
| 701 | cont_int a; a.insert(cont_int::value_type(0, 9)); a.insert(cont_int::value_type(1, 9)); a.insert(cont_int::value_type(2, 9)); |
| 702 | boost::intrusive::test::test_iterator_random< cont_int >(a); |
| 703 | if(boost::report_errors() != 0) { |
| 704 | return 1; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | #include <boost/container/detail/config_end.hpp> |
| 712 | |