1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/container/detail/config_begin.hpp>
11 #include <boost/container/slist.hpp>
12 #include <boost/container/node_allocator.hpp>
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"
22 using namespace boost::container
;
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
> >;
32 template class boost::container::slist
33 < test::movable_and_copyable_int
34 , node_allocator
<test::movable_and_copyable_int
> >;
42 slist
<recursive_slist
> slist_
;
43 slist
<recursive_slist
>::iterator it_
;
44 slist
<recursive_slist
>::const_iterator cit_
;
46 recursive_slist
&operator=(const recursive_slist
&o
)
47 { slist_
= o
.slist_
; return *this; }
50 void recursive_slist_test()//Test for recursive types
52 slist
<recursive_slist
> recursive_list_list
;
55 template<class VoidAllocator
>
56 struct GetAllocatorCont
58 template<class ValueType
>
61 typedef slist
< ValueType
62 , typename allocator_traits
<VoidAllocator
>
63 ::template portable_rebind_alloc
<ValueType
>::type
68 template<class VoidAllocator
>
69 int test_cont_variants()
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
;
76 if(test::list_test
<MyCont
, false>())
78 if(test::list_test
<MyMoveCont
, false>())
80 if(test::list_test
<MyCopyMoveCont
, false>())
82 if(test::list_test
<MyCopyMoveCont
, false>())
84 if(test::list_test
<MyCopyCont
, false>())
90 bool test_support_for_initializer_list()
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());
97 if(sl
!= expected_list
)
102 slist
<int> sl
= {1, 2};
104 if(sl
!= expected_list
)
108 slist
<int> sl({ 1, 2 }, slist
<int>::allocator_type());
110 if (sl
!= expected_list
)
114 slist
<int> sl
= {4, 5};
116 if(sl
!= expected_list
)
121 slist
<int> sl
= {15};
122 sl
.insert(sl
.cbegin(), {5, 10});
123 if(sl
!= expected_list
)
129 sl
.insert_after(sl
.cbegin(), {10, 15});
130 if(sl
!= expected_list
)
138 struct boost_container_slist
;
141 namespace container
{
145 struct alloc_propagate_base
<boost_container_slist
>
147 template <class T
, class Allocator
>
150 typedef boost::container::slist
<T
, Allocator
> type
;
158 recursive_slist_test();
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
);
167 slist
<recursive_slist
> recursive
, copy
;
168 //Test to test both move emulations
174 ////////////////////////////////////
175 // Testing allocator implementations
176 ////////////////////////////////////
178 if(test_cont_variants
< std::allocator
<void> >()){
179 std::cerr
<< "test_cont_variants< std::allocator<void> > failed" << std::endl
;
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
;
188 ////////////////////////////////////
190 ////////////////////////////////////
191 const test::EmplaceOptions Options
= (test::EmplaceOptions
)
192 (test::EMPLACE_FRONT
| test::EMPLACE_AFTER
| test::EMPLACE_BEFORE
| test::EMPLACE_AFTER
);
194 if(!boost::container::test::test_emplace
195 < slist
<test::EmplaceInt
>, Options
>())
198 ////////////////////////////////////
199 // Allocator propagation testing
200 ////////////////////////////////////
201 if(!boost::container::test::test_propagate_allocator
<boost_container_slist
>())
204 ////////////////////////////////////
206 ////////////////////////////////////
207 if(!test_support_for_initializer_list())
210 ////////////////////////////////////
212 ////////////////////////////////////
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) {
223 #include <boost/container/detail/config_end.hpp>