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