////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include "print_container.hpp" #include "dummy_test_allocator.hpp" #include "movable_int.hpp" #include "set_test.hpp" #include "propagate_allocator_test.hpp" #include "emplace_test.hpp" #include #include using namespace boost::container; namespace boost { namespace container { //Explicit instantiation to detect compilation errors //flat_set template class flat_set < test::movable_and_copyable_int , std::less , test::dummy_test_allocator >; template class flat_set < test::movable_and_copyable_int , std::less , test::simple_allocator >; template class flat_set < test::movable_and_copyable_int , std::less , std::allocator >; template class flat_set < test::movable_and_copyable_int , std::less , allocator >; template class flat_set < test::movable_and_copyable_int , std::less , adaptive_pool >; template class flat_set < test::movable_and_copyable_int , std::less , node_allocator >; //flat_multiset template class flat_multiset < test::movable_and_copyable_int , std::less , test::dummy_test_allocator >; template class flat_multiset < test::movable_and_copyable_int , std::less , test::simple_allocator >; template class flat_multiset < test::movable_and_copyable_int , std::less , std::allocator >; template class flat_multiset < test::movable_and_copyable_int , std::less , allocator >; template class flat_multiset < test::movable_and_copyable_int , std::less , adaptive_pool >; template class flat_multiset < test::movable_and_copyable_int , std::less , node_allocator >; //As flat container iterators are typedefs for vector::[const_]iterator, //no need to explicit instantiate them }} //boost::container //Test recursive structures class recursive_flat_set { public: recursive_flat_set(const recursive_flat_set &c) : id_(c.id_), flat_set_(c.flat_set_) {} recursive_flat_set & operator =(const recursive_flat_set &c) { id_ = c.id_; flat_set_= c.flat_set_; return *this; } int id_; flat_set flat_set_; friend bool operator< (const recursive_flat_set &a, const recursive_flat_set &b) { return a.id_ < b.id_; } }; //Test recursive structures class recursive_flat_multiset { public: recursive_flat_multiset(const recursive_flat_multiset &c) : id_(c.id_), flat_multiset_(c.flat_multiset_) {} recursive_flat_multiset & operator =(const recursive_flat_multiset &c) { id_ = c.id_; flat_multiset_= c.flat_multiset_; return *this; } int id_; flat_multiset flat_multiset_; friend bool operator< (const recursive_flat_multiset &a, const recursive_flat_multiset &b) { return a.id_ < b.id_; } }; template void test_move() { //Now test move semantics C original; C move_ctor(boost::move(original)); C move_assign; move_assign = boost::move(move_ctor); move_assign.swap(original); } template class flat_tree_propagate_test_wrapper : public container_detail::flat_tree, std::less, A> { BOOST_COPYABLE_AND_MOVABLE(flat_tree_propagate_test_wrapper) typedef container_detail::flat_tree, std::less, A> Base; public: flat_tree_propagate_test_wrapper() : Base() {} flat_tree_propagate_test_wrapper(const flat_tree_propagate_test_wrapper &x) : Base(x) {} flat_tree_propagate_test_wrapper(BOOST_RV_REF(flat_tree_propagate_test_wrapper) x) : Base(boost::move(static_cast(x))) {} flat_tree_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(flat_tree_propagate_test_wrapper) x) { this->Base::operator=(x); return *this; } flat_tree_propagate_test_wrapper &operator=(BOOST_RV_REF(flat_tree_propagate_test_wrapper) x) { this->Base::operator=(boost::move(static_cast(x))); return *this; } void swap(flat_tree_propagate_test_wrapper &x) { this->Base::swap(x); } }; namespace boost{ namespace container { namespace test{ bool flat_tree_ordered_insertion_test() { using namespace boost::container; const std::size_t NumElements = 100; //Ordered insertion multiset { std::multiset int_mset; for(std::size_t i = 0; i != NumElements; ++i){ int_mset.insert(static_cast(i)); } //Construction insertion flat_multiset fmset(ordered_range, int_mset.begin(), int_mset.end()); if(!CheckEqualContainers(&int_mset, &fmset)) return false; //Insertion when empty fmset.clear(); fmset.insert(ordered_range, int_mset.begin(), int_mset.end()); if(!CheckEqualContainers(&int_mset, &fmset)) return false; //Re-insertion fmset.insert(ordered_range, int_mset.begin(), int_mset.end()); std::multiset int_mset2(int_mset); int_mset2.insert(int_mset.begin(), int_mset.end()); if(!CheckEqualContainers(&int_mset2, &fmset)) return false; //Re-re-insertion fmset.insert(ordered_range, int_mset2.begin(), int_mset2.end()); std::multiset int_mset4(int_mset2); int_mset4.insert(int_mset2.begin(), int_mset2.end()); if(!CheckEqualContainers(&int_mset4, &fmset)) return false; //Re-re-insertion of even std::multiset int_even_mset; for(std::size_t i = 0; i < NumElements; i+=2){ int_mset.insert(static_cast(i)); } fmset.insert(ordered_range, int_even_mset.begin(), int_even_mset.end()); int_mset4.insert(int_even_mset.begin(), int_even_mset.end()); if(!CheckEqualContainers(&int_mset4, &fmset)) return false; } //Ordered insertion set { std::set int_set; for(std::size_t i = 0; i != NumElements; ++i){ int_set.insert(static_cast(i)); } //Construction insertion flat_set fset(ordered_unique_range, int_set.begin(), int_set.end()); if(!CheckEqualContainers(&int_set, &fset)) return false; //Insertion when empty fset.clear(); fset.insert(ordered_unique_range, int_set.begin(), int_set.end()); if(!CheckEqualContainers(&int_set, &fset)) return false; //Re-insertion fset.insert(ordered_unique_range, int_set.begin(), int_set.end()); std::set int_set2(int_set); int_set2.insert(int_set.begin(), int_set.end()); if(!CheckEqualContainers(&int_set2, &fset)) return false; //Re-re-insertion fset.insert(ordered_unique_range, int_set2.begin(), int_set2.end()); std::set int_set4(int_set2); int_set4.insert(int_set2.begin(), int_set2.end()); if(!CheckEqualContainers(&int_set4, &fset)) return false; //Re-re-insertion of even std::set int_even_set; for(std::size_t i = 0; i < NumElements; i+=2){ int_set.insert(static_cast(i)); } fset.insert(ordered_unique_range, int_even_set.begin(), int_even_set.end()); int_set4.insert(int_even_set.begin(), int_even_set.end()); if(!CheckEqualContainers(&int_set4, &fset)) return false; } return true; } }}} template struct GetAllocatorSet { template struct apply { typedef flat_set < ValueType , std::less , typename allocator_traits ::template portable_rebind_alloc::type > set_type; typedef flat_multiset < ValueType , std::less , typename allocator_traits ::template portable_rebind_alloc::type > multiset_type; }; }; template int test_set_variants() { typedef typename GetAllocatorSet::template apply::set_type MySet; typedef typename GetAllocatorSet::template apply::set_type MyMoveSet; typedef typename GetAllocatorSet::template apply::set_type MyCopyMoveSet; typedef typename GetAllocatorSet::template apply::set_type MyCopySet; typedef typename GetAllocatorSet::template apply::multiset_type MyMultiSet; typedef typename GetAllocatorSet::template apply::multiset_type MyMoveMultiSet; typedef typename GetAllocatorSet::template apply::multiset_type MyCopyMoveMultiSet; typedef typename GetAllocatorSet::template apply::multiset_type MyCopyMultiSet; typedef std::set MyStdSet; typedef std::multiset MyStdMultiSet; if (0 != test::set_test< MySet ,MyStdSet ,MyMultiSet ,MyStdMultiSet>()){ std::cout << "Error in set_test" << std::endl; return 1; } if (0 != test::set_test< MyMoveSet ,MyStdSet ,MyMoveMultiSet ,MyStdMultiSet>()){ std::cout << "Error in set_test" << std::endl; return 1; } if (0 != test::set_test< MyCopyMoveSet ,MyStdSet ,MyCopyMoveMultiSet ,MyStdMultiSet>()){ std::cout << "Error in set_test" << std::endl; return 1; } if (0 != test::set_test< MyCopySet ,MyStdSet ,MyCopyMultiSet ,MyStdMultiSet>()){ std::cout << "Error in set_test" << std::endl; return 1; } return 0; } int main() { using namespace boost::container::test; //Allocator argument container { flat_set set_((std::allocator())); flat_multiset multiset_((std::allocator())); } //Now test move semantics { test_move >(); test_move >(); } if(!flat_tree_ordered_insertion_test()){ return 1; } if(test_set_variants< std::allocator >()){ std::cerr << "test_set_variants< std::allocator > failed" << std::endl; return 1; } if(test_set_variants< allocator >()){ std::cerr << "test_set_variants< allocator > failed" << std::endl; return 1; } if(test_set_variants< node_allocator >()){ std::cerr << "test_set_variants< node_allocator > failed" << std::endl; return 1; } if(test_set_variants< adaptive_pool >()){ std::cerr << "test_set_variants< adaptive_pool > failed" << std::endl; return 1; } const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC); if(!boost::container::test::test_emplace, SetOptions>()) return 1; if(!boost::container::test::test_emplace, SetOptions>()) return 1; if(!boost::container::test::test_propagate_allocator()) return 1; return 0; } #include