• 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/intrusive/list.hpp>
12 #include <boost/intrusive/slist.hpp>
13 #include <boost/intrusive/bs_set.hpp>
14 #include <boost/intrusive/set.hpp>
15 #include <boost/intrusive/avl_set.hpp>
16 #include <boost/intrusive/sg_set.hpp>
17 #include <boost/intrusive/treap_set.hpp>
18 #include <boost/intrusive/splay_set.hpp>
19 #include <boost/intrusive/detail/mpl.hpp>
20 
21 #include <boost/core/lightweight_test.hpp>
22 #include <boost/aligned_storage.hpp>
23 #include <boost/static_assert.hpp>
24 #include <cstring>
25 #include <new>
26 
27 using namespace boost::intrusive;
28 
29 struct Type
30    : list_base_hook<>
31    , slist_base_hook<>
32    , set_base_hook<>
33    , avl_set_base_hook<>
34    , bs_set_base_hook<>
35 {};
36 
37 typedef boost::aligned_storage<sizeof(void*)*4>::type buffer_t;
38 
39 static buffer_t buffer_0x00;
40 static buffer_t buffer_0xFF;
41 
42 template<class Iterator>
on_0x00_buffer()43 const Iterator &on_0x00_buffer()
44 {
45    BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
46    return * ::new(std::memset(&buffer_0x00, 0x00, sizeof(buffer_0x00))) Iterator();
47 }
48 
49 template<class Iterator>
on_0xFF_buffer()50 const Iterator &on_0xFF_buffer()
51 {
52    BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator));
53    return * ::new(std::memset(&buffer_0xFF, 0xFF, sizeof(buffer_0xFF))) Iterator();
54 }
55 
56 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reverse_iterator)
BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator)57 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator)
58 
59 
60 template<class Container>
61 void check_null_iterators()
62 {
63    typedef typename Container::iterator               iterator;
64    typedef typename Container::const_iterator         const_iterator;
65    typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
66       (::, Container
67       ,reverse_iterator, iterator)                    reverse_iterator;
68    typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
69       (::, Container
70       ,const_reverse_iterator, const_iterator)        const_reverse_iterator;
71 
72    BOOST_TEST(on_0xFF_buffer<iterator>()               == on_0x00_buffer<iterator>());
73    BOOST_TEST(on_0xFF_buffer<const_iterator>()         == on_0x00_buffer<const_iterator>());
74    BOOST_TEST(on_0xFF_buffer<reverse_iterator>()       == on_0x00_buffer<reverse_iterator>());
75    BOOST_TEST(on_0xFF_buffer<const_reverse_iterator>() == on_0x00_buffer<const_reverse_iterator>());
76 }
77 
main()78 int main()
79 {
80    check_null_iterators< list<Type> >();
81    check_null_iterators< slist<Type> >();
82    check_null_iterators< bs_set<Type> >();
83    check_null_iterators< set<Type> >();
84    check_null_iterators< multiset<Type> >();
85    check_null_iterators< avl_set<Type> >();
86    check_null_iterators< avl_multiset<Type> >();
87    check_null_iterators< sg_set<Type> >();
88    check_null_iterators< sg_multiset<Type> >();
89    check_null_iterators< treap_set<Type> >();
90    check_null_iterators< treap_multiset<Type> >();
91    check_null_iterators< splay_set<Type> >();
92    check_null_iterators< splay_multiset<Type> >();
93 
94    return boost::report_errors();
95 }
96