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 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/container/detail/config_begin.hpp>
12 #include <boost/container/list.hpp>
13 #include <boost/container/adaptive_pool.hpp>
15 #include "dummy_test_allocator.hpp"
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"
23 using namespace boost::container
;
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
> >;
33 template class boost::container::list
34 < test::movable_and_copyable_int
35 , adaptive_pool
<test::movable_and_copyable_int
> >;
37 namespace container_detail
{
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>;
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_
;
58 recursive_list
&operator=(const recursive_list
&o
)
59 { list_
= o
.list_
; return *this; }
62 void recursive_list_test()//Test for recursive types
64 list
<recursive_list
> recursive
, copy
;
65 //Test to test both move emulations
71 template<class VoidAllocator
>
72 struct GetAllocatorCont
74 template<class ValueType
>
77 typedef list
< ValueType
78 , typename allocator_traits
<VoidAllocator
>
79 ::template portable_rebind_alloc
<ValueType
>::type
84 template<class VoidAllocator
>
85 int test_cont_variants()
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
;
92 if(test::list_test
<MyCont
, true>())
94 if(test::list_test
<MyMoveCont
, true>())
96 if(test::list_test
<MyCopyMoveCont
, true>())
98 if(test::list_test
<MyCopyMoveCont
, true>())
100 if(test::list_test
<MyCopyCont
, true>())
106 bool test_support_for_initializer_list()
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());
112 const list
<int> testConstructor((il
));
113 if(testConstructor
!= expectedList
)
116 const list
<int> testConstructorAllocator(il
, list
<int>::allocator_type());
117 if (testConstructorAllocator
!= expectedList
)
120 list
<int> testAssignOperator
= {10, 11};
121 testAssignOperator
= il
;
122 if(testAssignOperator
!= expectedList
)
125 list
<int> testAssignMethod
= {99};
126 testAssignMethod
= il
;
127 if(testAssignMethod
!= expectedList
)
130 list
<int> testInsertMethod
;
131 testInsertMethod
.insert(testInsertMethod
.cbegin(), il
);
132 if(testInsertMethod
!= testInsertMethod
)
140 struct boost_container_list
;
142 namespace boost
{ namespace container
{ namespace test
{
145 struct alloc_propagate_base
<boost_container_list
>
147 template <class T
, class Allocator
>
150 typedef boost::container::list
<T
, Allocator
> type
;
154 }}} //namespace boost::container::test
158 recursive_list_test();
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
);
168 ////////////////////////////////////
169 // Testing allocator implementations
170 ////////////////////////////////////
172 if(test_cont_variants
< std::allocator
<void> >()){
173 std::cerr
<< "test_cont_variants< std::allocator<void> > failed" << std::endl
;
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
;
182 ////////////////////////////////////
184 ////////////////////////////////////
185 const test::EmplaceOptions Options
= (test::EmplaceOptions
)(test::EMPLACE_BACK
| test::EMPLACE_FRONT
| test::EMPLACE_BEFORE
);
187 if(!boost::container::test::test_emplace
<list
<test::EmplaceInt
>, Options
>())
190 ////////////////////////////////////
191 // Allocator propagation testing
192 ////////////////////////////////////
193 if(!boost::container::test::test_propagate_allocator
<boost_container_list
>())
196 ////////////////////////////////////
198 ////////////////////////////////////
199 if(!test_support_for_initializer_list())
202 ////////////////////////////////////
204 ////////////////////////////////////
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) {
217 #include <boost/container/detail/config_end.hpp>