]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/slist_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / container / test / slist_test.cpp
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 #include <boost/container/detail/config_begin.hpp>
11 #include <boost/container/slist.hpp>
12 #include <boost/container/node_allocator.hpp>
13
14 #include <memory>
15 #include "dummy_test_allocator.hpp"
16 #include "movable_int.hpp"
17 #include "list_test.hpp"
18 #include "propagate_allocator_test.hpp"
19 #include "emplace_test.hpp"
20 #include "../../intrusive/test/iterator_test.hpp"
21
22 using namespace boost::container;
23
24 namespace boost {
25 namespace container {
26
27 //Explicit instantiation to detect compilation errors
28 template class boost::container::slist
29 < test::movable_and_copyable_int
30 , test::simple_allocator<test::movable_and_copyable_int> >;
31
32 template class boost::container::slist
33 < test::movable_and_copyable_int
34 , node_allocator<test::movable_and_copyable_int> >;
35
36 }}
37
38 class recursive_slist
39 {
40 public:
41 int id_;
42 slist<recursive_slist> slist_;
43 slist<recursive_slist>::iterator it_;
44 slist<recursive_slist>::const_iterator cit_;
45
46 recursive_slist &operator=(const recursive_slist &o)
47 { slist_ = o.slist_; return *this; }
48 };
49
50 void recursive_slist_test()//Test for recursive types
51 {
52 slist<recursive_slist> recursive_list_list;
53 }
54
55 template<class VoidAllocator>
56 struct GetAllocatorCont
57 {
58 template<class ValueType>
59 struct apply
60 {
61 typedef slist< ValueType
62 , typename allocator_traits<VoidAllocator>
63 ::template portable_rebind_alloc<ValueType>::type
64 > type;
65 };
66 };
67
68 template<class VoidAllocator>
69 int test_cont_variants()
70 {
71 typedef typename GetAllocatorCont<VoidAllocator>::template apply<int>::type MyCont;
72 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::movable_int>::type MyMoveCont;
73 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::movable_and_copyable_int>::type MyCopyMoveCont;
74 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::copyable_int>::type MyCopyCont;
75
76 if(test::list_test<MyCont, false>())
77 return 1;
78 if(test::list_test<MyMoveCont, false>())
79 return 1;
80 if(test::list_test<MyCopyMoveCont, false>())
81 return 1;
82 if(test::list_test<MyCopyMoveCont, false>())
83 return 1;
84 if(test::list_test<MyCopyCont, false>())
85 return 1;
86
87 return 0;
88 }
89
90 bool test_support_for_initializer_list()
91 {
92 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
93 const std::initializer_list<int> il = {5, 10, 15};
94 const slist<int> expected_list(il.begin(), il.end());
95 {
96 slist<int> sl = il;
97 if(sl != expected_list)
98 return false;
99 }
100
101 {
102 slist<int> sl = {1, 2};
103 sl = il;
104 if(sl != expected_list)
105 return false;
106 }
107 {
108 slist<int> sl({ 1, 2 }, slist<int>::allocator_type());
109 sl = il;
110 if (sl != expected_list)
111 return false;
112 }
113 {
114 slist<int> sl = {4, 5};
115 sl.assign(il);
116 if(sl != expected_list)
117 return false;
118 }
119
120 {
121 slist<int> sl = {15};
122 sl.insert(sl.cbegin(), {5, 10});
123 if(sl != expected_list)
124 return false;
125 }
126
127 {
128 slist<int> sl = {5};
129 sl.insert_after(sl.cbegin(), {10, 15});
130 if(sl != expected_list)
131 return false;
132 }
133 return true;
134 #endif
135 return true;
136 }
137
138 struct boost_container_slist;
139
140 namespace boost {
141 namespace container {
142 namespace test {
143
144 template<>
145 struct alloc_propagate_base<boost_container_slist>
146 {
147 template <class T, class Allocator>
148 struct apply
149 {
150 typedef boost::container::slist<T, Allocator> type;
151 };
152 };
153
154 }}}
155
156 int main ()
157 {
158 recursive_slist_test();
159 {
160 //Now test move semantics
161 slist<recursive_slist> original;
162 slist<recursive_slist> move_ctor(boost::move(original));
163 slist<recursive_slist> move_assign;
164 move_assign = boost::move(move_ctor);
165 move_assign.swap(original);
166 {
167 slist<recursive_slist> recursive, copy;
168 //Test to test both move emulations
169 if(!copy.size()){
170 copy = recursive;
171 }
172 }
173 }
174 ////////////////////////////////////
175 // Testing allocator implementations
176 ////////////////////////////////////
177 // std:allocator
178 if(test_cont_variants< std::allocator<void> >()){
179 std::cerr << "test_cont_variants< std::allocator<void> > failed" << std::endl;
180 return 1;
181 }
182 // boost::container::node_allocator
183 if(test_cont_variants< node_allocator<void> >()){
184 std::cerr << "test_cont_variants< node_allocator<void> > failed" << std::endl;
185 return 1;
186 }
187
188 ////////////////////////////////////
189 // Emplace testing
190 ////////////////////////////////////
191 const test::EmplaceOptions Options = (test::EmplaceOptions)
192 (test::EMPLACE_FRONT | test::EMPLACE_AFTER | test::EMPLACE_BEFORE | test::EMPLACE_AFTER);
193
194 if(!boost::container::test::test_emplace
195 < slist<test::EmplaceInt>, Options>())
196 return 1;
197
198 ////////////////////////////////////
199 // Allocator propagation testing
200 ////////////////////////////////////
201 if(!boost::container::test::test_propagate_allocator<boost_container_slist>())
202 return 1;
203
204 ////////////////////////////////////
205 // Initializer lists
206 ////////////////////////////////////
207 if(!test_support_for_initializer_list())
208 return 1;
209
210 ////////////////////////////////////
211 // Iterator testing
212 ////////////////////////////////////
213 {
214 typedef boost::container::slist<int> vector_int;
215 vector_int a; a.push_front(2); a.push_front(1); a.push_front(0);
216 boost::intrusive::test::test_iterator_forward< boost::container::slist<int> >(a);
217 if(boost::report_errors() != 0) {
218 return 1;
219 }
220 }
221 }
222
223 #include <boost/container/detail/config_end.hpp>
224