blob: f081dbe0ecb075837d23f2efebb25e0aedf5da9b [file] [log] [blame]
Brian Silvermanfad8f552018-08-04 23:36:19 -07001//////////////////////////////////////////////////////////////////////////////
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 <new>
28
29using namespace boost::container;
30
31typedef boost::container::dtl::aligned_storage<sizeof(void*)*4>::type buffer_t;
32
33static buffer_t buffer_0x00;
34static buffer_t buffer_0xFF;
35
36template<class Iterator>
37const Iterator &on_0x00_buffer()
38{
39 BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
40 return * ::new(std::memset(&buffer_0x00, 0x00, sizeof(buffer_0x00))) Iterator();
41}
42
43template<class Iterator>
44const Iterator &on_0xFF_buffer()
45{
46 BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
47 return * ::new(std::memset(&buffer_0xFF, 0xFF, sizeof(buffer_0xFF))) Iterator();
48}
49
50namespace boost {
51namespace container {
52namespace test {
53
54BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reverse_iterator)
55BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator)
56
57}}} //namespace boost::container::test {
58
59template<class Container>
60void check_null_iterators()
61{
62 typedef typename Container::iterator iterator;
63 typedef typename Container::const_iterator const_iterator;
64 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
65 (boost::container::test::, Container
66 ,reverse_iterator, iterator) reverse_iterator;
67 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
68 (boost::container::test::, Container
69 ,const_reverse_iterator, const_iterator) const_reverse_iterator;
70
71 BOOST_TEST(on_0xFF_buffer<iterator>() == on_0x00_buffer<iterator>());
72 BOOST_TEST(on_0xFF_buffer<const_iterator>() == on_0x00_buffer<const_iterator>());
73 BOOST_TEST(on_0xFF_buffer<reverse_iterator>() == on_0x00_buffer<reverse_iterator>());
74 BOOST_TEST(on_0xFF_buffer<const_reverse_iterator>() == on_0x00_buffer<const_reverse_iterator>());
75}
76
77int main()
78{
79 check_null_iterators< vector<int> >();
80 check_null_iterators< deque<int> >();
81 check_null_iterators< stable_vector<int> >();
82 check_null_iterators< static_vector<int, 1> >();
83 check_null_iterators< string >();
84 check_null_iterators< list<int> >();
85 check_null_iterators< slist<int> >();
86 check_null_iterators< map<int, int> >();
87 check_null_iterators< multimap<int, int> >();
88 check_null_iterators< set<int> >();
89 check_null_iterators< multiset<int> >();
90 check_null_iterators< flat_set<int> >();
91 check_null_iterators< flat_multiset<int> >();
92 check_null_iterators< flat_map<int, int> >();
93 check_null_iterators< flat_multimap<int, int> >();
94
95 return boost::report_errors();
96}