1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2004-2012. 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)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/container/detail/config_begin.hpp>
12 #include <boost/container/set.hpp>
13 #include <boost/container/map.hpp>
14 #include "print_container.hpp"
15 #include "movable_int.hpp"
16 #include "dummy_test_allocator.hpp"
17 #include "set_test.hpp"
18 #include "map_test.hpp"
19 #include "propagate_allocator_test.hpp"
20 #include "emplace_test.hpp"
22 using namespace boost::container;
24 //Alias standard types
25 typedef std::set<int> MyStdSet;
26 typedef std::multiset<int> MyStdMultiSet;
27 typedef std::map<int, int> MyStdMap;
28 typedef std::multimap<int, int> MyStdMultiMap;
30 //Alias non-movable types
31 typedef set<int> MyBoostSet;
32 typedef multiset<int> MyBoostMultiSet;
33 typedef map<int, int> MyBoostMap;
34 typedef multimap<int, int> MyBoostMultiMap;
37 typedef set<test::movable_int> MyMovableBoostSet;
38 typedef multiset<test::movable_int> MyMovableBoostMultiSet;
39 typedef map<test::movable_int, test::movable_int> MyMovableBoostMap;
40 typedef multimap<test::movable_int, test::movable_int> MyMovableBoostMultiMap;
41 typedef set<test::movable_and_copyable_int> MyMoveCopyBoostSet;
42 typedef set<test::copyable_int> MyCopyBoostSet;
43 typedef multiset<test::movable_and_copyable_int> MyMoveCopyBoostMultiSet;
44 typedef multiset<test::copyable_int> MyCopyBoostMultiSet;
45 typedef map<test::movable_and_copyable_int
46 ,test::movable_and_copyable_int> MyMoveCopyBoostMap;
47 typedef multimap<test::movable_and_copyable_int
48 ,test::movable_and_copyable_int> MyMoveCopyBoostMultiMap;
49 typedef map<test::copyable_int
50 ,test::copyable_int> MyCopyBoostMap;
51 typedef multimap<test::copyable_int
52 ,test::copyable_int> MyCopyBoostMultiMap;
57 //Explicit instantiation to detect compilation errors
61 < test::movable_and_copyable_int
62 , test::movable_and_copyable_int
63 , std::less<test::movable_and_copyable_int>
64 , test::dummy_test_allocator
65 < std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
69 < test::movable_and_copyable_int
70 , test::movable_and_copyable_int
71 , std::less<test::movable_and_copyable_int>
72 , test::simple_allocator
73 < std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
77 < test::movable_and_copyable_int
78 , test::movable_and_copyable_int
79 , std::less<test::movable_and_copyable_int>
81 < std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
85 template class multimap
86 < test::movable_and_copyable_int
87 , test::movable_and_copyable_int
88 , std::less<test::movable_and_copyable_int>
89 , test::dummy_test_allocator
90 < std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
93 template class multimap
94 < test::movable_and_copyable_int
95 , test::movable_and_copyable_int
96 , std::less<test::movable_and_copyable_int>
97 , test::simple_allocator
98 < std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
101 template class multimap
102 < test::movable_and_copyable_int
103 , test::movable_and_copyable_int
104 , std::less<test::movable_and_copyable_int>
106 < std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> >
111 < test::movable_and_copyable_int
112 , std::less<test::movable_and_copyable_int>
113 , test::dummy_test_allocator<test::movable_and_copyable_int>
117 < test::movable_and_copyable_int
118 , std::less<test::movable_and_copyable_int>
119 , test::simple_allocator<test::movable_and_copyable_int>
123 < test::movable_and_copyable_int
124 , std::less<test::movable_and_copyable_int>
125 , std::allocator<test::movable_and_copyable_int>
129 template class multiset
130 < test::movable_and_copyable_int
131 , std::less<test::movable_and_copyable_int>
132 , test::dummy_test_allocator<test::movable_and_copyable_int>
135 template class multiset
136 < test::movable_and_copyable_int
137 , std::less<test::movable_and_copyable_int>
138 , test::simple_allocator<test::movable_and_copyable_int>
141 template class multiset
142 < test::movable_and_copyable_int
143 , std::less<test::movable_and_copyable_int>
144 , std::allocator<test::movable_and_copyable_int>
147 }} //boost::container
149 //Test recursive structures
153 recursive_set & operator=(const recursive_set &x)
154 { id_ = x.id_; set_ = x.set_; return *this; }
157 set<recursive_set> set_;
158 friend bool operator< (const recursive_set &a, const recursive_set &b)
159 { return a.id_ < b.id_; }
165 recursive_map & operator=(const recursive_map &x)
166 { id_ = x.id_; map_ = x.map_; return *this; }
169 map<recursive_map, recursive_map> map_;
170 friend bool operator< (const recursive_map &a, const recursive_map &b)
171 { return a.id_ < b.id_; }
174 //Test recursive structures
175 class recursive_multiset
178 recursive_multiset & operator=(const recursive_multiset &x)
179 { id_ = x.id_; multiset_ = x.multiset_; return *this; }
182 multiset<recursive_multiset> multiset_;
183 friend bool operator< (const recursive_multiset &a, const recursive_multiset &b)
184 { return a.id_ < b.id_; }
187 class recursive_multimap
190 recursive_multimap & operator=(const recursive_multimap &x)
191 { id_ = x.id_; multimap_ = x.multimap_; return *this; }
194 multimap<recursive_multimap, recursive_multimap> multimap_;
195 friend bool operator< (const recursive_multimap &a, const recursive_multimap &b)
196 { return a.id_ < b.id_; }
202 //Now test move semantics
205 C move_ctor(boost::move(original));
207 move_assign.emplace();
208 move_assign = boost::move(move_ctor);
209 move_assign.swap(original);
212 template<class T, class A>
213 class tree_propagate_test_wrapper
214 : public container_detail::rbtree<T, T, container_detail::identity<T>, std::less<T>, A>
216 BOOST_COPYABLE_AND_MOVABLE(tree_propagate_test_wrapper)
217 typedef container_detail::rbtree<T, T, container_detail::identity<T>, std::less<T>, A> Base;
219 tree_propagate_test_wrapper()
223 tree_propagate_test_wrapper(const tree_propagate_test_wrapper &x)
227 tree_propagate_test_wrapper(BOOST_RV_REF(tree_propagate_test_wrapper) x)
228 : Base(boost::move(static_cast<Base&>(x)))
231 tree_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(tree_propagate_test_wrapper) x)
232 { this->Base::operator=(x); return *this; }
234 tree_propagate_test_wrapper &operator=(BOOST_RV_REF(tree_propagate_test_wrapper) x)
235 { this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
237 void swap(tree_propagate_test_wrapper &x)
238 { this->Base::swap(x); }
243 //Recursive container instantiation
245 set<recursive_set> set_;
246 multiset<recursive_multiset> multiset_;
247 map<recursive_map, recursive_map> map_;
248 multimap<recursive_multimap, recursive_multimap> multimap_;
250 //Now test move semantics
252 test_move<set<recursive_set> >();
253 test_move<multiset<recursive_multiset> >();
254 test_move<map<recursive_map, recursive_map> >();
255 test_move<multimap<recursive_multimap, recursive_multimap> >();
258 //using namespace boost::container::detail;
260 if(0 != test::set_test<MyBoostSet
267 if(0 != test::set_test_copyable<MyBoostSet
274 if(0 != test::set_test<MyMovableBoostSet
276 ,MyMovableBoostMultiSet
281 if(0 != test::set_test<MyMoveCopyBoostSet
283 ,MyMoveCopyBoostMultiSet
288 if(0 != test::set_test_copyable<MyMoveCopyBoostSet
290 ,MyMoveCopyBoostMultiSet
295 if(0 != test::set_test<MyCopyBoostSet
302 if(0 != test::set_test_copyable<MyCopyBoostSet
309 if (0 != test::map_test<MyBoostMap
316 if(0 != test::map_test_copyable<MyBoostMap
323 if (0 != test::map_test<MyMovableBoostMap
325 ,MyMovableBoostMultiMap
330 if (0 != test::map_test<MyMoveCopyBoostMap
332 ,MyMoveCopyBoostMultiMap
337 if (0 != test::map_test_copyable<MyMoveCopyBoostMap
339 ,MyMoveCopyBoostMultiMap
344 if (0 != test::map_test<MyCopyBoostMap
351 if (0 != test::map_test_copyable<MyCopyBoostMap
358 const test::EmplaceOptions SetOptions = (test::EmplaceOptions)(test::EMPLACE_HINT | test::EMPLACE_ASSOC);
359 if(!boost::container::test::test_emplace<set<test::EmplaceInt>, SetOptions>())
361 if(!boost::container::test::test_emplace<multiset<test::EmplaceInt>, SetOptions>())
363 const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
364 if(!boost::container::test::test_emplace<map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
366 if(!boost::container::test::test_emplace<multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
368 if(!boost::container::test::test_propagate_allocator<tree_propagate_test_wrapper>())
374 #include <boost/container/detail/config_end.hpp>