]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/intrusive/test/unordered_set_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / intrusive / test / unordered_set_test.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-2015.
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12 #include <boost/intrusive/unordered_set.hpp>
13 #include <boost/intrusive/pointer_traits.hpp>
14 #include <boost/intrusive/detail/iterator.hpp>
15 #include "itestvalue.hpp"
16 #include "smart_ptr.hpp"
17 #include "common_functors.hpp"
18 #include <vector>
19 #include <set>
20 #include <boost/detail/lightweight_test.hpp>
21 #include "test_macros.hpp"
22 #include "test_container.hpp"
23 #include "unordered_test_common.hpp"
24 #include "unordered_test.hpp"
25
26 using namespace boost::intrusive;
27
28 template < class ValueTraits, bool ConstantTimeSize, bool CacheBegin, bool CompareHash, bool Incremental, bool Map, bool DefaultHolder >
29 struct rebinder
30 {
31 typedef unordered_rebinder_common<ValueTraits, DefaultHolder, Map> common_t;
32 typedef typename ValueContainer< typename ValueTraits::value_type >::type value_cont_type;
33
34 template < class Option1 =void
35 , class Option2 =void
36 >
37 struct container
38 {
39 typedef unordered_set
40 < typename common_t::value_type
41 , value_traits<ValueTraits>
42 , constant_time_size<ConstantTimeSize>
43 , cache_begin<CacheBegin>
44 , compare_hash<CompareHash>
45 , incremental<Incremental>
46 , typename common_t::holder_opt
47 , typename common_t::key_of_value_opt
48 , Option1
49 , Option2
50 > type;
51 BOOST_STATIC_ASSERT((key_type_tester<typename common_t::key_of_value_opt, type>::value));
52 BOOST_STATIC_ASSERT((!boost::intrusive::test::is_multikey_true<type>::value));
53 };
54 };
55
56 enum HookType
57 {
58 Base,
59 Member,
60 NonMember
61 };
62
63 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map, HookType Type>
64 class test_main_template;
65
66 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
67 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Base>
68 {
69 public:
70 static void execute()
71 {
72 typedef testvalue<unordered_hooks<VoidPointer> > value_type;
73 static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
74 typedef typename ValueContainer< value_type >::type value_cont_type;
75 value_cont_type data (6);
76 for (int i = 0; i < 6; ++i)
77 data[i].value_ = random_init[i];
78
79 typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
80 //base
81 typedef typename detail::if_c
82 < ConstantTimeSize
83 , typename testval_traits_t::base_value_traits
84 , typename testval_traits_t::auto_base_value_traits //store_hash<true>
85 >::type base_hook_t;
86 test::test_unordered
87 < //cache_begin, compare_hash, incremental
88 rebinder<base_hook_t, ConstantTimeSize, ConstantTimeSize, !ConstantTimeSize, !!ConstantTimeSize, Map, DefaultHolder>
89 >::test_all(data);
90 }
91 };
92
93 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
94 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, Member>
95 {
96 public:
97 static void execute()
98 {
99 typedef testvalue<unordered_hooks<VoidPointer> > value_type;
100 static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
101 typedef typename ValueContainer< value_type >::type value_cont_type;
102 value_cont_type data (6);
103 for (int i = 0; i < 6; ++i)
104 data[i].value_ = random_init[i];
105
106 typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
107 //member
108 typedef typename detail::if_c
109 < ConstantTimeSize
110 , typename testval_traits_t::member_value_traits //optimize_multikey<true>
111 , typename testval_traits_t::auto_member_value_traits //store_hash<true>, optimize_multikey<true>
112 >::type member_hook_t;
113 test::test_unordered
114 < //cache_begin, compare_hash, incremental
115 rebinder<member_hook_t, ConstantTimeSize, false, !ConstantTimeSize, false, !ConstantTimeSize, DefaultHolder>
116 >::test_all(data);
117 }
118 };
119
120 template<class VoidPointer, bool ConstantTimeSize, bool DefaultHolder, bool Map>
121 class test_main_template<VoidPointer, ConstantTimeSize, DefaultHolder, Map, NonMember>
122
123 {
124 public:
125 static void execute()
126 {
127 typedef testvalue<unordered_hooks<VoidPointer> > value_type;
128 static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
129 typedef typename ValueContainer< value_type >::type value_cont_type;
130 value_cont_type data (6);
131 for (int i = 0; i < 6; ++i)
132 data[i].value_ = random_init[i];
133
134 typedef testvalue_traits< unordered_hooks<VoidPointer> > testval_traits_t;
135 //nonmember
136 test::test_unordered
137 < //cache_begin, compare_hash, incremental
138 rebinder<typename testval_traits_t::nonhook_value_traits, ConstantTimeSize, false, false, false, Map, DefaultHolder>
139 >::test_all(data);
140 }
141 };
142
143 int main()
144 {
145 //VoidPointer x ConstantTimeSize x Map x DefaultHolder
146
147 //void pointer
148 test_main_template<void*, false, false, false, Base>::execute();
149 test_main_template<void*, false, true, false, Member>::execute();
150 test_main_template<void*, true, false, false, NonMember>::execute();
151 test_main_template<void*, true, true, false, Base>::execute();
152
153 //smart_ptr
154 test_main_template<smart_ptr<void>, false, false, false, Member>::execute();
155 test_main_template<smart_ptr<void>, false, true, false, NonMember>::execute();
156 test_main_template<smart_ptr<void>, true, false, false, Base>::execute();
157 test_main_template<smart_ptr<void>, true, true, false, Member>::execute();
158
159 ////bounded_ptr (bool ConstantTimeSize, bool Map)
160 //test_main_template_bptr< false, false >::execute();
161 //test_main_template_bptr< false, true >::execute();
162 //test_main_template_bptr< true, false >::execute();
163 //test_main_template_bptr< true, true >::execute();
164
165 return boost::report_errors();
166 }