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