|
12 | 12 | // |
13 | 13 | ///////////////////////////////////////////////////////////////////////////// |
14 | 14 | #include <boost/container/vector.hpp> //vector |
| 15 | +#include <algorithm> //std::next_permutation |
15 | 16 | #include <boost/intrusive/detail/config_begin.hpp> |
16 | 17 | #include "common_functors.hpp" |
17 | 18 | #include <boost/intrusive/options.hpp> |
@@ -428,6 +429,36 @@ void test_generic_assoc<ContainerDefiner>::test_clone(value_cont_type& values) |
428 | 429 | testset2.clear_and_dispose(test::delete_noexcept_disposer<value_type>()); |
429 | 430 | BOOST_TEST (testset2.empty()); |
430 | 431 | } |
| 432 | + { //In non-balanced trees the shape |
| 433 | + //depends on the insertion order, so test all insertion orders |
| 434 | + typedef typename ContainerDefiner::template container |
| 435 | + <>::type assoc_type; |
| 436 | + typedef typename assoc_type::value_type value_type; |
| 437 | + |
| 438 | + const std::size_t NumValues = 5; |
| 439 | + value_cont_type vals(NumValues); |
| 440 | + std::size_t order[NumValues]; |
| 441 | + for(std::size_t i = 0; i != NumValues; ++i){ |
| 442 | + (&vals[i])->value_ = (int)i; |
| 443 | + order[i] = i; |
| 444 | + } |
| 445 | + |
| 446 | + do{ |
| 447 | + assoc_type testset1; |
| 448 | + for(std::size_t i = 0; i != NumValues; ++i){ |
| 449 | + testset1.insert(vals[order[i]]); |
| 450 | + } |
| 451 | + assoc_type testset2; |
| 452 | + testset2.clone_from(testset1, test::new_cloner<value_type>(), test::delete_disposer<value_type>()); |
| 453 | + BOOST_TEST (testset2 == testset1); |
| 454 | + BOOST_TEST (testset2.size() == NumValues); |
| 455 | + BOOST_TEST (*testset2.begin() == *testset1.begin()); |
| 456 | + BOOST_TEST (*testset2.rbegin() == *testset1.rbegin()); |
| 457 | + testset2.check(); |
| 458 | + testset2.clear_and_dispose(test::delete_noexcept_disposer<value_type>()); |
| 459 | + testset1.clear(); |
| 460 | + }while(std::next_permutation(order, order + NumValues)); |
| 461 | + } |
431 | 462 | } |
432 | 463 |
|
433 | 464 | template<class ContainerDefiner> |
|
0 commit comments