File: null_iterators_test.cpp

package info (click to toggle)
boost1.74 1.74.0%2Bds1-21
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 463,588 kB
  • sloc: cpp: 3,338,117; xml: 131,293; python: 33,088; ansic: 14,292; asm: 4,038; sh: 3,353; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (146 lines) | stat: -rw-r--r-- 5,066 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////

#include <boost/container/vector.hpp>
#include <boost/container/deque.hpp>
#include <boost/container/stable_vector.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/container/string.hpp>
#include <boost/container/list.hpp>
#include <boost/container/slist.hpp>
#include <boost/container/map.hpp>
#include <boost/container/set.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/intrusive/detail/mpl.hpp>

#include <boost/core/lightweight_test.hpp>
#include <boost/static_assert.hpp>
#include <cstring>
#include <iterator>
#include <new>

using namespace boost::container;

typedef boost::container::dtl::aligned_storage<sizeof(void*)*4>::type buffer_t;

static buffer_t buffer_0x00;
static buffer_t buffer_0xFF;

template<class Iterator>
const Iterator &on_0x00_buffer()
{
   BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
   return * ::new(std::memset(&buffer_0x00, 0x00, sizeof(buffer_0x00))) Iterator();
}

template<class Iterator>
const Iterator &on_0xFF_buffer()
{
   BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
   return * ::new(std::memset(&buffer_0xFF, 0xFF, sizeof(buffer_0xFF))) Iterator();
}

namespace boost {
namespace container {
namespace test {

BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reverse_iterator)
BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator)

}}}   //namespace boost::container::test {

template<class RandomAccessIterator>
void check_plus_zero_impl(RandomAccessIterator it)
{
  RandomAccessIterator cpy(it + 0);
  BOOST_TEST(cpy == it);
}

template<class Container, class Category>
void check_plus_zero(const Category&)
{}

template<class Container>
void check_plus_zero(const std::random_access_iterator_tag&)
{
  check_plus_zero_impl(typename Container::iterator());
  check_plus_zero_impl(typename Container::const_iterator());
  check_plus_zero_impl(typename Container::reverse_iterator());
  check_plus_zero_impl(typename Container::const_reverse_iterator());
  Container c;
  check_plus_zero_impl(c.begin());
  check_plus_zero_impl(c.cbegin());
  check_plus_zero_impl(c.rbegin());
  check_plus_zero_impl(c.crbegin());
}

template<class Container>
void check_plus_zero()
{
  typedef typename Container::iterator iterator;
  typedef typename std::iterator_traits<iterator>::iterator_category category;
  category tag;
  check_plus_zero<Container>(tag);
}

template<class Container>
void check_null_iterators()
{
   typedef typename Container::iterator               iterator;
   typedef typename Container::const_iterator         const_iterator;
   typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
      (boost::container::test::, Container
      ,reverse_iterator, iterator)                    reverse_iterator;
   typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
      (boost::container::test::, Container
      ,const_reverse_iterator, const_iterator)        const_reverse_iterator;

   BOOST_TEST(on_0xFF_buffer<iterator>()               == on_0x00_buffer<iterator>());
   BOOST_TEST(on_0xFF_buffer<const_iterator>()         == on_0x00_buffer<const_iterator>());
   BOOST_TEST(on_0xFF_buffer<reverse_iterator>()       == on_0x00_buffer<reverse_iterator>());
   BOOST_TEST(on_0xFF_buffer<const_reverse_iterator>() == on_0x00_buffer<const_reverse_iterator>());
}

int main()
{
   check_null_iterators< vector<int> >();
   check_plus_zero< vector<int> >();
   check_null_iterators< deque<int> >();
   check_plus_zero< deque<int> >();
   check_null_iterators< stable_vector<int> >();
   check_plus_zero< stable_vector<int> >();
   check_null_iterators< static_vector<int, 1> >();
   check_plus_zero< static_vector<int, 1> >();
   check_null_iterators< string >();
   check_plus_zero< string >();
   check_null_iterators< list<int> >();
   check_plus_zero< list<int> >();
   check_null_iterators< slist<int> >();
   check_plus_zero< slist<int> >();
   check_null_iterators< map<int, int> >();
   check_plus_zero< map<int, int> >();
   check_null_iterators< multimap<int, int> >();
   check_plus_zero< multimap<int, int> >();
   check_null_iterators< set<int> >();
   check_plus_zero< set<int> >();
   check_null_iterators< multiset<int> >();
   check_plus_zero< multiset<int> >();
   check_null_iterators< flat_set<int> >();
   check_plus_zero< flat_set<int> >();
   check_null_iterators< flat_multiset<int> >();
   check_plus_zero< flat_multiset<int> >();
   check_null_iterators< flat_map<int, int> >();
   check_plus_zero< flat_map<int, int> >();
   check_null_iterators< flat_multimap<int, int> >();
   check_plus_zero< flat_multimap<int, int> >();

   return boost::report_errors();
}