1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2014-2014. 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/vector.hpp>
12 #include <boost/container/deque.hpp>
13 #include <boost/container/stable_vector.hpp>
14 #include <boost/container/static_vector.hpp>
15 #include <boost/container/string.hpp>
16 #include <boost/container/list.hpp>
17 #include <boost/container/slist.hpp>
18 #include <boost/container/map.hpp>
19 #include <boost/container/set.hpp>
20 #include <boost/container/flat_set.hpp>
21 #include <boost/container/flat_map.hpp>
22 #include <boost/intrusive/detail/mpl.hpp>
24 #include <boost/core/lightweight_test.hpp>
25 #include <boost/static_assert.hpp>
30 using namespace boost::container
;
32 typedef boost::container::dtl::aligned_storage
<sizeof(void*)*4>::type buffer_t
;
34 static buffer_t buffer_0x00
;
35 static buffer_t buffer_0xFF
;
37 template<class Iterator
>
38 const Iterator
&on_0x00_buffer()
40 BOOST_STATIC_ASSERT(sizeof(buffer_t
) >= sizeof(Iterator
));
41 return * ::new(std::memset(&buffer_0x00
, 0x00, sizeof(buffer_0x00
))) Iterator();
44 template<class Iterator
>
45 const Iterator
&on_0xFF_buffer()
47 BOOST_STATIC_ASSERT(sizeof(buffer_t
) >= sizeof(Iterator
));
48 return * ::new(std::memset(&buffer_0xFF
, 0xFF, sizeof(buffer_0xFF
))) Iterator();
55 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reverse_iterator
)
56 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator
)
58 }}} //namespace boost::container::test {
60 template<class RandomAccessIterator
>
61 void check_plus_zero_impl(RandomAccessIterator it
)
63 RandomAccessIterator
cpy(it
+ 0);
64 BOOST_TEST(cpy
== it
);
67 template<class Container
, class Category
>
68 void check_plus_zero(const Category
&)
71 template<class Container
>
72 void check_plus_zero(const std::random_access_iterator_tag
&)
74 check_plus_zero_impl(typename
Container::iterator());
75 check_plus_zero_impl(typename
Container::const_iterator());
76 check_plus_zero_impl(typename
Container::reverse_iterator());
77 check_plus_zero_impl(typename
Container::const_reverse_iterator());
79 check_plus_zero_impl(c
.begin());
80 check_plus_zero_impl(c
.cbegin());
81 check_plus_zero_impl(c
.rbegin());
82 check_plus_zero_impl(c
.crbegin());
85 template<class Container
>
86 void check_plus_zero()
88 typedef typename
Container::iterator iterator
;
89 typedef typename
std::iterator_traits
<iterator
>::iterator_category category
;
91 check_plus_zero
<Container
>(tag
);
94 template<class Container
>
95 void check_null_iterators()
97 typedef typename
Container::iterator iterator
;
98 typedef typename
Container::const_iterator const_iterator
;
99 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
100 (boost::container::test::, Container
101 ,reverse_iterator
, iterator
) reverse_iterator
;
102 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
103 (boost::container::test::, Container
104 ,const_reverse_iterator
, const_iterator
) const_reverse_iterator
;
106 BOOST_TEST(on_0xFF_buffer
<iterator
>() == on_0x00_buffer
<iterator
>());
107 BOOST_TEST(on_0xFF_buffer
<const_iterator
>() == on_0x00_buffer
<const_iterator
>());
108 BOOST_TEST(on_0xFF_buffer
<reverse_iterator
>() == on_0x00_buffer
<reverse_iterator
>());
109 BOOST_TEST(on_0xFF_buffer
<const_reverse_iterator
>() == on_0x00_buffer
<const_reverse_iterator
>());
114 check_null_iterators
< vector
<int> >();
115 check_plus_zero
< vector
<int> >();
116 check_null_iterators
< deque
<int> >();
117 check_plus_zero
< deque
<int> >();
118 check_null_iterators
< stable_vector
<int> >();
119 check_plus_zero
< stable_vector
<int> >();
120 check_null_iterators
< static_vector
<int, 1> >();
121 check_plus_zero
< static_vector
<int, 1> >();
122 check_null_iterators
< string
>();
123 check_plus_zero
< string
>();
124 check_null_iterators
< list
<int> >();
125 check_plus_zero
< list
<int> >();
126 check_null_iterators
< slist
<int> >();
127 check_plus_zero
< slist
<int> >();
128 check_null_iterators
< map
<int, int> >();
129 check_plus_zero
< map
<int, int> >();
130 check_null_iterators
< multimap
<int, int> >();
131 check_plus_zero
< multimap
<int, int> >();
132 check_null_iterators
< set
<int> >();
133 check_plus_zero
< set
<int> >();
134 check_null_iterators
< multiset
<int> >();
135 check_plus_zero
< multiset
<int> >();
136 check_null_iterators
< flat_set
<int> >();
137 check_plus_zero
< flat_set
<int> >();
138 check_null_iterators
< flat_multiset
<int> >();
139 check_plus_zero
< flat_multiset
<int> >();
140 check_null_iterators
< flat_map
<int, int> >();
141 check_plus_zero
< flat_map
<int, int> >();
142 check_null_iterators
< flat_multimap
<int, int> >();
143 check_plus_zero
< flat_multimap
<int, int> >();
145 return boost::report_errors();