////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2004-2012. 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 "print_container.hpp" #include "movable_int.hpp" #include "dummy_test_allocator.hpp" #include "set_test.hpp" #include "map_test.hpp" #include "propagate_allocator_test.hpp" #include "emplace_test.hpp" using namespace boost::container; //Alias standard types typedef std::set MyStdSet; typedef std::multiset MyStdMultiSet; typedef std::map MyStdMap; typedef std::multimap MyStdMultiMap; //Alias non-movable types typedef set MyBoostSet; typedef multiset MyBoostMultiSet; typedef map MyBoostMap; typedef multimap MyBoostMultiMap; //Alias movable types typedef set MyMovableBoostSet; typedef multiset MyMovableBoostMultiSet; typedef map MyMovableBoostMap; typedef multimap MyMovableBoostMultiMap; typedef set MyMoveCopyBoostSet; typedef set MyCopyBoostSet; typedef multiset MyMoveCopyBoostMultiSet; typedef multiset MyCopyBoostMultiSet; typedef map MyMoveCopyBoostMap; typedef multimap MyMoveCopyBoostMultiMap; typedef map MyCopyBoostMap; typedef multimap MyCopyBoostMultiMap; namespace boost { namespace container { //Explicit instantiation to detect compilation errors //map template class map < test::movable_and_copyable_int , test::movable_and_copyable_int , std::less , test::dummy_test_allocator < std::pair > >; template class map < test::movable_and_copyable_int , test::movable_and_copyable_int , std::less , test::simple_allocator < std::pair > >; template class map < test::movable_and_copyable_int , test::movable_and_copyable_int , std::less , std::allocator < std::pair > >; //multimap template class multimap < test::movable_and_copyable_int , test::movable_and_copyable_int , std::less , test::dummy_test_allocator < std::pair > >; template class multimap < test::movable_and_copyable_int , test::movable_and_copyable_int , std::less , test::simple_allocator < std::pair > >; template class multimap < test::movable_and_copyable_int , test::movable_and_copyable_int , std::less , std::allocator < std::pair > >; //set template class set < test::movable_and_copyable_int , std::less , test::dummy_test_allocator >; template class set < test::movable_and_copyable_int , std::less , test::simple_allocator >; template class set < test::movable_and_copyable_int , std::less , std::allocator >; //multiset template class multiset < test::movable_and_copyable_int , std::less , test::dummy_test_allocator >; template class multiset < test::movable_and_copyable_int , std::less , test::simple_allocator >; template class multiset < test::movable_and_copyable_int , std::less , std::allocator >; }} //boost::container //Test recursive structures class recursive_set { public: recursive_set & operator=(const recursive_set &x) { id_ = x.id_; set_ = x.set_; return *this; } int id_; set set_; friend bool operator< (const recursive_set &a, const recursive_set &b) { return a.id_ < b.id_; } }; class recursive_map { public: recursive_map & operator=(const recursive_map &x) { id_ = x.id_; map_ = x.map_; return *this; } int id_; map map_; friend bool operator< (const recursive_map &a, const recursive_map &b) { return a.id_ < b.id_; } }; //Test recursive structures class recursive_multiset { public: recursive_multiset & operator=(const recursive_multiset &x) { id_ = x.id_; multiset_ = x.multiset_; return *this; } int id_; multiset multiset_; friend bool operator< (const recursive_multiset &a, const recursive_multiset &b) { return a.id_ < b.id_; } }; class recursive_multimap { public: recursive_multimap & operator=(const recursive_multimap &x) { id_ = x.id_; multimap_ = x.multimap_; return *this; } int id_; multimap multimap_; friend bool operator< (const recursive_multimap &a, const recursive_multimap &b) { return a.id_ < b.id_; } }; template void test_move() { //Now test move semantics C original; original.emplace(); C move_ctor(boost::move(original)); C move_assign; move_assign.emplace(); move_assign = boost::move(move_ctor); move_assign.swap(original); } template class tree_propagate_test_wrapper : public container_detail::rbtree, std::less, A> { BOOST_COPYABLE_AND_MOVABLE(tree_propagate_test_wrapper) typedef container_detail::rbtree, std::less, A> Base; public: tree_propagate_test_wrapper() : Base() {} tree_propagate_test_wrapper(const tree_propagate_test_wrapper &x) : Base(x) {} tree_propagate_test_wrapper(BOOST_RV_REF(tree_propagate_test_wrapper) x) : Base(boost::move(static_cast(x))) {} tree_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(tree_propagate_test_wrapper) x) { this->Base::operator=(x); return *this; } tree_propagate_test_wrapper &operator=(BOOST_RV_REF(tree_propagate_test_wrapper) x) { this->Base::operator=(boost::move(static_cast(x))); return *this; } void swap(tree_propagate_test_wrapper &x) { this->Base::swap(x); } }; int main () { //Recursive container instantiation { set set_; multiset multiset_; map map_; multimap multimap_; } //Allocator argument container { set set_((std::allocator())); multiset multiset_((std::allocator())); map map_((std::allocator >())); multimap multimap_((std::allocator >())); } //Now test move semantics { test_move >(); test_move >(); test_move >(); test_move >(); } if(0 != test::set_test()){ return 1; } if(0 != test::set_test_copyable()){ return 1; } if(0 != test::set_test()){ return 1; } if(0 != test::set_test()){ return 1; } if(0 != test::set_test_copyable()){ return 1; } if(0 != test::set_test()){ return 1; } if(0 != test::set_test_copyable()){ return 1; } if (0 != test::map_test()){ return 1; } if(0 != test::map_test_copyable()){ return 1; } if (0 != test::map_test()){ return 1; } if (0 != test::map_test()){ return 1; } if (0 != test::map_test_copyable()){ return 1; } if (0 != test::map_test()){ return 1; } if (0 != test::map_test_copyable()){ 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; const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR); if(!boost::container::test::test_emplace, MapOptions>()) return 1; if(!boost::container::test::test_emplace, MapOptions>()) return 1; if(!boost::container::test::test_propagate_allocator()) return 1; return 0; } #include