• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //////////////////////////////////////////////////////////////////////////////
2 //
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)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 
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>
23 
24 #include <boost/core/lightweight_test.hpp>
25 #include <boost/static_assert.hpp>
26 #include <cstring>
27 #include <iterator>
28 #include <new>
29 
30 using namespace boost::container;
31 
32 typedef boost::container::dtl::aligned_storage<sizeof(void*)*4>::type buffer_t;
33 
34 static buffer_t buffer_0x00;
35 static buffer_t buffer_0xFF;
36 
37 template<class Iterator>
on_0x00_buffer()38 const Iterator &on_0x00_buffer()
39 {
40    BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
41    return * ::new(std::memset(&buffer_0x00, 0x00, sizeof(buffer_0x00))) Iterator();
42 }
43 
44 template<class Iterator>
on_0xFF_buffer()45 const Iterator &on_0xFF_buffer()
46 {
47    BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
48    return * ::new(std::memset(&buffer_0xFF, 0xFF, sizeof(buffer_0xFF))) Iterator();
49 }
50 
51 namespace boost {
52 namespace container {
53 namespace test {
54 
55 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reverse_iterator)
56 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator)
57 
58 }}}   //namespace boost::container::test {
59 
60 template<class RandomAccessIterator>
check_plus_zero_impl(RandomAccessIterator it)61 void check_plus_zero_impl(RandomAccessIterator it)
62 {
63   RandomAccessIterator cpy(it + 0);
64   BOOST_TEST(cpy == it);
65 }
66 
67 template<class Container, class Category>
check_plus_zero(const Category &)68 void check_plus_zero(const Category&)
69 {}
70 
71 template<class Container>
check_plus_zero(const std::random_access_iterator_tag &)72 void check_plus_zero(const std::random_access_iterator_tag&)
73 {
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());
78   Container c;
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());
83 }
84 
85 template<class Container>
check_plus_zero()86 void check_plus_zero()
87 {
88   typedef typename Container::iterator iterator;
89   typedef typename std::iterator_traits<iterator>::iterator_category category;
90   category tag;
91   check_plus_zero<Container>(tag);
92 }
93 
94 template<class Container>
check_null_iterators()95 void check_null_iterators()
96 {
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;
105 
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>());
110 }
111 
main()112 int main()
113 {
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> >();
144 
145    return boost::report_errors();
146 }
147