Chris@16
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2007-2013
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@16
|
10 //
|
Chris@16
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_INTRUSIVE_OPTIONS_HPP
|
Chris@16
|
14 #define BOOST_INTRUSIVE_OPTIONS_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/intrusive/detail/config_begin.hpp>
|
Chris@16
|
17 #include <boost/intrusive/intrusive_fwd.hpp>
|
Chris@16
|
18 #include <boost/intrusive/link_mode.hpp>
|
Chris@16
|
19 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@16
|
20 #include <boost/intrusive/detail/utilities.hpp>
|
Chris@16
|
21 #include <boost/static_assert.hpp>
|
Chris@16
|
22
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost {
|
Chris@16
|
25 namespace intrusive {
|
Chris@16
|
26
|
Chris@16
|
27 /// @cond
|
Chris@16
|
28
|
Chris@16
|
29 //typedef void default_tag;
|
Chris@16
|
30 struct default_tag;
|
Chris@16
|
31 struct member_tag;
|
Chris@16
|
32
|
Chris@16
|
33 namespace detail{
|
Chris@16
|
34
|
Chris@16
|
35 struct default_hook_tag{};
|
Chris@16
|
36
|
Chris@16
|
37 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
38
|
Chris@16
|
39 #define BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER) \
|
Chris@16
|
40 struct BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER : public default_hook_tag\
|
Chris@16
|
41 {\
|
Chris@16
|
42 template <class T>\
|
Chris@16
|
43 struct apply\
|
Chris@16
|
44 { typedef typename T::BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER type; };\
|
Chris@16
|
45 }\
|
Chris@16
|
46
|
Chris@16
|
47 BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_list_hook);
|
Chris@16
|
48 BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_slist_hook);
|
Chris@16
|
49 BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_rbtree_hook);
|
Chris@16
|
50 BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_hashtable_hook);
|
Chris@16
|
51 BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_avltree_hook);
|
Chris@16
|
52 BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_bstree_hook);
|
Chris@16
|
53 //BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_splaytree_hook);
|
Chris@16
|
54 //BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_sgtree_hook);
|
Chris@16
|
55 //BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_treap_hook);
|
Chris@16
|
56
|
Chris@16
|
57 #undef BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION
|
Chris@16
|
58
|
Chris@16
|
59 #endif //BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
60
|
Chris@16
|
61 template <class ValueTraits>
|
Chris@16
|
62 struct eval_value_traits
|
Chris@16
|
63 {
|
Chris@16
|
64 typedef typename ValueTraits::value_traits type;
|
Chris@16
|
65 };
|
Chris@16
|
66
|
Chris@16
|
67 template<class ValueTraits>
|
Chris@16
|
68 struct get_real_value_traits
|
Chris@16
|
69 : public eval_if_c
|
Chris@16
|
70 < external_value_traits_bool_is_true<ValueTraits>::value
|
Chris@16
|
71 , eval_value_traits<ValueTraits>
|
Chris@16
|
72 , identity<ValueTraits>
|
Chris@16
|
73 >
|
Chris@16
|
74 {};
|
Chris@16
|
75
|
Chris@16
|
76 template <class BucketTraits>
|
Chris@16
|
77 struct eval_bucket_traits
|
Chris@16
|
78 {
|
Chris@16
|
79 typedef typename BucketTraits::bucket_traits type;
|
Chris@16
|
80 };
|
Chris@16
|
81
|
Chris@16
|
82 template <class T, class BaseHook>
|
Chris@16
|
83 struct concrete_hook_base_value_traits
|
Chris@16
|
84 {
|
Chris@16
|
85 typedef typename BaseHook::hooktags tags;
|
Chris@16
|
86 typedef bhtraits
|
Chris@16
|
87 < T
|
Chris@16
|
88 , typename tags::node_traits
|
Chris@16
|
89 , tags::link_mode
|
Chris@16
|
90 , typename tags::tag
|
Chris@16
|
91 , tags::type> type;
|
Chris@16
|
92 };
|
Chris@16
|
93
|
Chris@16
|
94 template <class BaseHook>
|
Chris@16
|
95 struct concrete_hook_base_node_traits
|
Chris@16
|
96 { typedef typename BaseHook::hooktags::node_traits type; };
|
Chris@16
|
97
|
Chris@16
|
98 template <class T, class AnyToSomeHook_ProtoValueTraits>
|
Chris@16
|
99 struct any_hook_base_value_traits
|
Chris@16
|
100 {
|
Chris@16
|
101 //AnyToSomeHook value_traits derive from a generic_hook
|
Chris@16
|
102 //The generic_hook is configured with any_node_traits
|
Chris@16
|
103 //and AnyToSomeHook::value_traits with the correct
|
Chris@16
|
104 //node traits for the container, so use node_traits
|
Chris@16
|
105 //from AnyToSomeHook_ProtoValueTraits and the rest of
|
Chris@16
|
106 //elements from the hooktags member of the generic_hook
|
Chris@16
|
107 typedef AnyToSomeHook_ProtoValueTraits proto_value_traits;
|
Chris@16
|
108 typedef bhtraits
|
Chris@16
|
109 < T
|
Chris@16
|
110 , typename proto_value_traits::node_traits
|
Chris@16
|
111 , proto_value_traits::hooktags::link_mode
|
Chris@16
|
112 , typename proto_value_traits::hooktags::tag
|
Chris@16
|
113 , proto_value_traits::hooktags::type
|
Chris@16
|
114 > type;
|
Chris@16
|
115 };
|
Chris@16
|
116
|
Chris@16
|
117 template <class BaseHook>
|
Chris@16
|
118 struct any_hook_base_node_traits
|
Chris@16
|
119 { typedef typename BaseHook::node_traits type; };
|
Chris@16
|
120
|
Chris@16
|
121 template<class T, class BaseHook>
|
Chris@16
|
122 struct get_base_value_traits
|
Chris@16
|
123 {
|
Chris@16
|
124 typedef typename detail::eval_if_c
|
Chris@16
|
125 < internal_any_hook_bool_is_true<BaseHook>::value
|
Chris@16
|
126 , any_hook_base_value_traits<T, BaseHook>
|
Chris@16
|
127 , concrete_hook_base_value_traits<T, BaseHook>
|
Chris@16
|
128 >::type type;
|
Chris@16
|
129 };
|
Chris@16
|
130
|
Chris@16
|
131 template<class BaseHook>
|
Chris@16
|
132 struct get_base_node_traits
|
Chris@16
|
133 {
|
Chris@16
|
134 typedef typename detail::eval_if_c
|
Chris@16
|
135 < internal_any_hook_bool_is_true<BaseHook>::value
|
Chris@16
|
136 , any_hook_base_node_traits<BaseHook>
|
Chris@16
|
137 , concrete_hook_base_node_traits<BaseHook>
|
Chris@16
|
138 >::type type;
|
Chris@16
|
139 };
|
Chris@16
|
140
|
Chris@16
|
141 template<class T, class MemberHook>
|
Chris@16
|
142 struct get_member_value_traits
|
Chris@16
|
143 {
|
Chris@16
|
144 typedef typename MemberHook::member_value_traits type;
|
Chris@16
|
145 };
|
Chris@16
|
146
|
Chris@16
|
147 template<class MemberHook>
|
Chris@16
|
148 struct get_member_node_traits
|
Chris@16
|
149 {
|
Chris@16
|
150 typedef typename MemberHook::member_value_traits::node_traits type;
|
Chris@16
|
151 };
|
Chris@16
|
152
|
Chris@16
|
153 template<class T, class SupposedValueTraits>
|
Chris@16
|
154 struct get_value_traits
|
Chris@16
|
155 {
|
Chris@16
|
156 typedef typename detail::eval_if_c
|
Chris@16
|
157 <detail::is_convertible<SupposedValueTraits*, detail::default_hook_tag*>::value
|
Chris@16
|
158 ,detail::apply<SupposedValueTraits, T>
|
Chris@16
|
159 ,detail::identity<SupposedValueTraits>
|
Chris@16
|
160 >::type supposed_value_traits;
|
Chris@16
|
161
|
Chris@16
|
162 //...if it's a default hook
|
Chris@16
|
163 typedef typename detail::eval_if_c
|
Chris@16
|
164 < internal_base_hook_bool_is_true<supposed_value_traits>::value
|
Chris@16
|
165 //...get it's internal value traits using
|
Chris@16
|
166 //the provided T value type.
|
Chris@16
|
167 , get_base_value_traits<T, supposed_value_traits>
|
Chris@16
|
168 //...else use it's internal value traits tag
|
Chris@16
|
169 //(member hooks and custom value traits are in this group)
|
Chris@16
|
170 , detail::eval_if_c
|
Chris@16
|
171 < internal_member_value_traits<supposed_value_traits>::value
|
Chris@16
|
172 , get_member_value_traits<T, supposed_value_traits>
|
Chris@16
|
173 , detail::identity<supposed_value_traits>
|
Chris@16
|
174 >
|
Chris@16
|
175 >::type type;
|
Chris@16
|
176 };
|
Chris@16
|
177
|
Chris@16
|
178 template<class ValueTraits>
|
Chris@16
|
179 struct get_explicit_node_traits
|
Chris@16
|
180 {
|
Chris@16
|
181 typedef typename ValueTraits::node_traits type;
|
Chris@16
|
182 };
|
Chris@16
|
183
|
Chris@16
|
184 template<class SupposedValueTraits>
|
Chris@16
|
185 struct get_node_traits
|
Chris@16
|
186 {
|
Chris@16
|
187 typedef SupposedValueTraits supposed_value_traits;
|
Chris@16
|
188 //...if it's a base hook
|
Chris@16
|
189 typedef typename detail::eval_if_c
|
Chris@16
|
190 < internal_base_hook_bool_is_true<supposed_value_traits>::value
|
Chris@16
|
191 //...get it's internal value traits using
|
Chris@16
|
192 //the provided T value type.
|
Chris@16
|
193 , get_base_node_traits<supposed_value_traits>
|
Chris@16
|
194 //...else use it's internal value traits tag
|
Chris@16
|
195 //(member hooks and custom value traits are in this group)
|
Chris@16
|
196 , detail::eval_if_c
|
Chris@16
|
197 < internal_member_value_traits<supposed_value_traits>::value
|
Chris@16
|
198 , get_member_node_traits<supposed_value_traits>
|
Chris@16
|
199 , get_explicit_node_traits<supposed_value_traits>
|
Chris@16
|
200 >
|
Chris@16
|
201 >::type type;
|
Chris@16
|
202 };
|
Chris@16
|
203
|
Chris@16
|
204 } //namespace detail{
|
Chris@16
|
205
|
Chris@16
|
206 /// @endcond
|
Chris@16
|
207
|
Chris@16
|
208 //!This option setter specifies if the intrusive
|
Chris@16
|
209 //!container stores its size as a member to
|
Chris@16
|
210 //!obtain constant-time size() member.
|
Chris@16
|
211 template<bool Enabled>
|
Chris@16
|
212 struct constant_time_size
|
Chris@16
|
213 {
|
Chris@16
|
214 /// @cond
|
Chris@16
|
215 template<class Base>
|
Chris@16
|
216 struct pack : Base
|
Chris@16
|
217 {
|
Chris@16
|
218 static const bool constant_time_size = Enabled;
|
Chris@16
|
219 };
|
Chris@16
|
220 /// @endcond
|
Chris@16
|
221 };
|
Chris@16
|
222
|
Chris@16
|
223 //!This option setter specifies the type that
|
Chris@16
|
224 //!the container will use to store its size.
|
Chris@16
|
225 template<class SizeType>
|
Chris@16
|
226 struct size_type
|
Chris@16
|
227 {
|
Chris@16
|
228 /// @cond
|
Chris@16
|
229 template<class Base>
|
Chris@16
|
230 struct pack : Base
|
Chris@16
|
231 {
|
Chris@16
|
232 typedef SizeType size_type;
|
Chris@16
|
233 };
|
Chris@16
|
234 /// @endcond
|
Chris@16
|
235 };
|
Chris@16
|
236
|
Chris@16
|
237 //!This option setter specifies the strict weak ordering
|
Chris@16
|
238 //!comparison functor for the value type
|
Chris@16
|
239 template<class Compare>
|
Chris@16
|
240 struct compare
|
Chris@16
|
241 {
|
Chris@16
|
242 /// @cond
|
Chris@16
|
243 template<class Base>
|
Chris@16
|
244 struct pack : Base
|
Chris@16
|
245 {
|
Chris@16
|
246 typedef Compare compare;
|
Chris@16
|
247 };
|
Chris@16
|
248 /// @endcond
|
Chris@16
|
249 };
|
Chris@16
|
250
|
Chris@16
|
251 //!This option setter for scapegoat containers specifies if
|
Chris@16
|
252 //!the intrusive scapegoat container should use a non-variable
|
Chris@16
|
253 //!alpha value that does not need floating-point operations.
|
Chris@16
|
254 //!
|
Chris@16
|
255 //!If activated, the fixed alpha value is 1/sqrt(2). This
|
Chris@16
|
256 //!option also saves some space in the container since
|
Chris@16
|
257 //!the alpha value and some additional data does not need
|
Chris@16
|
258 //!to be stored in the container.
|
Chris@16
|
259 //!
|
Chris@16
|
260 //!If the user only needs an alpha value near 1/sqrt(2), this
|
Chris@16
|
261 //!option also improves performance since avoids logarithm
|
Chris@16
|
262 //!and division operations when rebalancing the tree.
|
Chris@16
|
263 template<bool Enabled>
|
Chris@16
|
264 struct floating_point
|
Chris@16
|
265 {
|
Chris@16
|
266 /// @cond
|
Chris@16
|
267 template<class Base>
|
Chris@16
|
268 struct pack : Base
|
Chris@16
|
269 {
|
Chris@16
|
270 static const bool floating_point = Enabled;
|
Chris@16
|
271 };
|
Chris@16
|
272 /// @endcond
|
Chris@16
|
273 };
|
Chris@16
|
274
|
Chris@16
|
275 //!This option setter specifies the equality
|
Chris@16
|
276 //!functor for the value type
|
Chris@16
|
277 template<class Equal>
|
Chris@16
|
278 struct equal
|
Chris@16
|
279 {
|
Chris@16
|
280 /// @cond
|
Chris@16
|
281 template<class Base>
|
Chris@16
|
282 struct pack : Base
|
Chris@16
|
283 {
|
Chris@16
|
284 typedef Equal equal;
|
Chris@16
|
285 };
|
Chris@16
|
286 /// @endcond
|
Chris@16
|
287 };
|
Chris@16
|
288
|
Chris@16
|
289 //!This option setter specifies the equality
|
Chris@16
|
290 //!functor for the value type
|
Chris@16
|
291 template<class Priority>
|
Chris@16
|
292 struct priority
|
Chris@16
|
293 {
|
Chris@16
|
294 /// @cond
|
Chris@16
|
295 template<class Base>
|
Chris@16
|
296 struct pack : Base
|
Chris@16
|
297 {
|
Chris@16
|
298 typedef Priority priority;
|
Chris@16
|
299 };
|
Chris@16
|
300 /// @endcond
|
Chris@16
|
301 };
|
Chris@16
|
302
|
Chris@16
|
303 //!This option setter specifies the hash
|
Chris@16
|
304 //!functor for the value type
|
Chris@16
|
305 template<class Hash>
|
Chris@16
|
306 struct hash
|
Chris@16
|
307 {
|
Chris@16
|
308 /// @cond
|
Chris@16
|
309 template<class Base>
|
Chris@16
|
310 struct pack : Base
|
Chris@16
|
311 {
|
Chris@16
|
312 typedef Hash hash;
|
Chris@16
|
313 };
|
Chris@16
|
314 /// @endcond
|
Chris@16
|
315 };
|
Chris@16
|
316
|
Chris@16
|
317 //!This option setter specifies the relationship between the type
|
Chris@16
|
318 //!to be managed by the container (the value type) and the node to be
|
Chris@16
|
319 //!used in the node algorithms. It also specifies the linking policy.
|
Chris@16
|
320 template<typename ValueTraits>
|
Chris@16
|
321 struct value_traits
|
Chris@16
|
322 {
|
Chris@16
|
323 /// @cond
|
Chris@16
|
324 template<class Base>
|
Chris@16
|
325 struct pack : Base
|
Chris@16
|
326 {
|
Chris@16
|
327 typedef ValueTraits proto_value_traits;
|
Chris@16
|
328 };
|
Chris@16
|
329 /// @endcond
|
Chris@16
|
330 };
|
Chris@16
|
331
|
Chris@16
|
332 //!This option setter specifies the member hook the
|
Chris@16
|
333 //!container must use.
|
Chris@16
|
334 template< typename Parent
|
Chris@16
|
335 , typename MemberHook
|
Chris@16
|
336 , MemberHook Parent::* PtrToMember>
|
Chris@16
|
337 struct member_hook
|
Chris@16
|
338 {
|
Chris@16
|
339 /// @cond
|
Chris@16
|
340 /*
|
Chris@16
|
341 typedef typename MemberHook::hooktags::node_traits node_traits;
|
Chris@16
|
342 typedef typename node_traits::node node_type;
|
Chris@16
|
343 typedef node_type Parent::* Ptr2MemNode;
|
Chris@16
|
344 typedef mhtraits
|
Chris@16
|
345 < Parent
|
Chris@16
|
346 , node_traits
|
Chris@16
|
347 //This cast is really ugly but necessary to reduce template bloat.
|
Chris@16
|
348 //Since we control the layout between the hook and the node, and there is
|
Chris@16
|
349 //always single inheritance, the offset of the node is exactly the offset of
|
Chris@16
|
350 //the hook. Since the node type is shared between all member hooks, this saves
|
Chris@16
|
351 //quite a lot of symbol stuff.
|
Chris@16
|
352 , (Ptr2MemNode)PtrToMember
|
Chris@16
|
353 , MemberHook::hooktags::link_mode> member_value_traits;
|
Chris@16
|
354 */
|
Chris@16
|
355 typedef mhtraits
|
Chris@16
|
356 < Parent
|
Chris@16
|
357 , MemberHook
|
Chris@16
|
358 , PtrToMember
|
Chris@16
|
359 > member_value_traits;
|
Chris@16
|
360 template<class Base>
|
Chris@16
|
361 struct pack : Base
|
Chris@16
|
362 {
|
Chris@16
|
363 typedef member_value_traits proto_value_traits;
|
Chris@16
|
364 };
|
Chris@16
|
365 /// @endcond
|
Chris@16
|
366 };
|
Chris@16
|
367
|
Chris@16
|
368
|
Chris@16
|
369 //!This option setter specifies the function object that will
|
Chris@16
|
370 //!be used to convert between values to be inserted in a container
|
Chris@16
|
371 //!and the hook to be used for that purpose.
|
Chris@16
|
372 template< typename Functor>
|
Chris@16
|
373 struct function_hook
|
Chris@16
|
374 {
|
Chris@16
|
375 /// @cond
|
Chris@16
|
376 typedef fhtraits
|
Chris@16
|
377 <Functor> function_value_traits;
|
Chris@16
|
378 template<class Base>
|
Chris@16
|
379 struct pack : Base
|
Chris@16
|
380 {
|
Chris@16
|
381 typedef function_value_traits proto_value_traits;
|
Chris@16
|
382 };
|
Chris@16
|
383 /// @endcond
|
Chris@16
|
384 };
|
Chris@16
|
385
|
Chris@16
|
386
|
Chris@16
|
387 //!This option setter specifies that the container
|
Chris@16
|
388 //!must use the specified base hook
|
Chris@16
|
389 template<typename BaseHook>
|
Chris@16
|
390 struct base_hook
|
Chris@16
|
391 {
|
Chris@16
|
392 /// @cond
|
Chris@16
|
393 template<class Base>
|
Chris@16
|
394 struct pack : Base
|
Chris@16
|
395 {
|
Chris@16
|
396 typedef BaseHook proto_value_traits;
|
Chris@16
|
397 };
|
Chris@16
|
398 /// @endcond
|
Chris@16
|
399 };
|
Chris@16
|
400
|
Chris@16
|
401 //!This option setter specifies the type of
|
Chris@16
|
402 //!a void pointer. This will instruct the hook
|
Chris@16
|
403 //!to use this type of pointer instead of the
|
Chris@16
|
404 //!default one
|
Chris@16
|
405 template<class VoidPointer>
|
Chris@16
|
406 struct void_pointer
|
Chris@16
|
407 {
|
Chris@16
|
408 /// @cond
|
Chris@16
|
409 template<class Base>
|
Chris@16
|
410 struct pack : Base
|
Chris@16
|
411 {
|
Chris@16
|
412 typedef VoidPointer void_pointer;
|
Chris@16
|
413 };
|
Chris@16
|
414 /// @endcond
|
Chris@16
|
415 };
|
Chris@16
|
416
|
Chris@16
|
417 //!This option setter specifies the type of
|
Chris@16
|
418 //!the tag of a base hook. A type cannot have two
|
Chris@16
|
419 //!base hooks of the same type, so a tag can be used
|
Chris@16
|
420 //!to differentiate two base hooks with otherwise same type
|
Chris@16
|
421 template<class Tag>
|
Chris@16
|
422 struct tag
|
Chris@16
|
423 {
|
Chris@16
|
424 /// @cond
|
Chris@16
|
425 template<class Base>
|
Chris@16
|
426 struct pack : Base
|
Chris@16
|
427 {
|
Chris@16
|
428 typedef Tag tag;
|
Chris@16
|
429 };
|
Chris@16
|
430 /// @endcond
|
Chris@16
|
431 };
|
Chris@16
|
432
|
Chris@16
|
433 //!This option setter specifies the link mode
|
Chris@16
|
434 //!(normal_link, safe_link or auto_unlink)
|
Chris@16
|
435 template<link_mode_type LinkType>
|
Chris@16
|
436 struct link_mode
|
Chris@16
|
437 {
|
Chris@16
|
438 /// @cond
|
Chris@16
|
439 template<class Base>
|
Chris@16
|
440 struct pack : Base
|
Chris@16
|
441 {
|
Chris@16
|
442 static const link_mode_type link_mode = LinkType;
|
Chris@16
|
443 };
|
Chris@16
|
444 /// @endcond
|
Chris@16
|
445 };
|
Chris@16
|
446
|
Chris@16
|
447 //!This option setter specifies if the hook
|
Chris@16
|
448 //!should be optimized for size instead of for speed.
|
Chris@16
|
449 template<bool Enabled>
|
Chris@16
|
450 struct optimize_size
|
Chris@16
|
451 {
|
Chris@16
|
452 /// @cond
|
Chris@16
|
453 template<class Base>
|
Chris@16
|
454 struct pack : Base
|
Chris@16
|
455 {
|
Chris@16
|
456 static const bool optimize_size = Enabled;
|
Chris@16
|
457 };
|
Chris@16
|
458 /// @endcond
|
Chris@16
|
459 };
|
Chris@16
|
460
|
Chris@16
|
461 //!This option setter specifies if the list container should
|
Chris@16
|
462 //!use a linear implementation instead of a circular one.
|
Chris@16
|
463 template<bool Enabled>
|
Chris@16
|
464 struct linear
|
Chris@16
|
465 {
|
Chris@16
|
466 /// @cond
|
Chris@16
|
467 template<class Base>
|
Chris@16
|
468 struct pack : Base
|
Chris@16
|
469 {
|
Chris@16
|
470 static const bool linear = Enabled;
|
Chris@16
|
471 };
|
Chris@16
|
472 /// @endcond
|
Chris@16
|
473 };
|
Chris@16
|
474
|
Chris@16
|
475 //!This option setter specifies if the list container should
|
Chris@16
|
476 //!use a linear implementation instead of a circular one.
|
Chris@16
|
477 template<bool Enabled>
|
Chris@16
|
478 struct cache_last
|
Chris@16
|
479 {
|
Chris@16
|
480 /// @cond
|
Chris@16
|
481 template<class Base>
|
Chris@16
|
482 struct pack : Base
|
Chris@16
|
483 {
|
Chris@16
|
484 static const bool cache_last = Enabled;
|
Chris@16
|
485 };
|
Chris@16
|
486 /// @endcond
|
Chris@16
|
487 };
|
Chris@16
|
488
|
Chris@16
|
489 //!This option setter specifies the bucket traits
|
Chris@16
|
490 //!class for unordered associative containers. When this option is specified,
|
Chris@16
|
491 //!instead of using the default bucket traits, a user defined holder will be defined
|
Chris@16
|
492 template<class BucketTraits>
|
Chris@16
|
493 struct bucket_traits
|
Chris@16
|
494 {
|
Chris@16
|
495 /// @cond
|
Chris@16
|
496 template<class Base>
|
Chris@16
|
497 struct pack : Base
|
Chris@16
|
498 {
|
Chris@16
|
499 typedef BucketTraits bucket_traits;
|
Chris@16
|
500 };
|
Chris@16
|
501 /// @endcond
|
Chris@16
|
502 };
|
Chris@16
|
503
|
Chris@16
|
504 //!This option setter specifies if the unordered hook
|
Chris@16
|
505 //!should offer room to store the hash value.
|
Chris@16
|
506 //!Storing the hash in the hook will speed up rehashing
|
Chris@16
|
507 //!processes in applications where rehashing is frequent,
|
Chris@16
|
508 //!rehashing might throw or the value is heavy to hash.
|
Chris@16
|
509 template<bool Enabled>
|
Chris@16
|
510 struct store_hash
|
Chris@16
|
511 {
|
Chris@16
|
512 /// @cond
|
Chris@16
|
513 template<class Base>
|
Chris@16
|
514 struct pack : Base
|
Chris@16
|
515 {
|
Chris@16
|
516 static const bool store_hash = Enabled;
|
Chris@16
|
517 };
|
Chris@16
|
518 /// @endcond
|
Chris@16
|
519 };
|
Chris@16
|
520
|
Chris@16
|
521 //!This option setter specifies if the unordered hook
|
Chris@16
|
522 //!should offer room to store another link to another node
|
Chris@16
|
523 //!with the same key.
|
Chris@16
|
524 //!Storing this link will speed up lookups and insertions on
|
Chris@16
|
525 //!unordered_multiset containers with a great number of elements
|
Chris@16
|
526 //!with the same key.
|
Chris@16
|
527 template<bool Enabled>
|
Chris@16
|
528 struct optimize_multikey
|
Chris@16
|
529 {
|
Chris@16
|
530 /// @cond
|
Chris@16
|
531 template<class Base>
|
Chris@16
|
532 struct pack : Base
|
Chris@16
|
533 {
|
Chris@16
|
534 static const bool optimize_multikey = Enabled;
|
Chris@16
|
535 };
|
Chris@16
|
536 /// @endcond
|
Chris@16
|
537 };
|
Chris@16
|
538
|
Chris@16
|
539 //!This option setter specifies if the bucket array will be always power of two.
|
Chris@16
|
540 //!This allows using masks instead of the default modulo operation to determine
|
Chris@16
|
541 //!the bucket number from the hash value, leading to better performance.
|
Chris@16
|
542 //!In debug mode, if power of two buckets mode is activated, the bucket length
|
Chris@16
|
543 //!will be checked to through assertions to assure the bucket length is power of two.
|
Chris@16
|
544 template<bool Enabled>
|
Chris@16
|
545 struct power_2_buckets
|
Chris@16
|
546 {
|
Chris@16
|
547 /// @cond
|
Chris@16
|
548 template<class Base>
|
Chris@16
|
549 struct pack : Base
|
Chris@16
|
550 {
|
Chris@16
|
551 static const bool power_2_buckets = Enabled;
|
Chris@16
|
552 };
|
Chris@16
|
553 /// @endcond
|
Chris@16
|
554 };
|
Chris@16
|
555
|
Chris@16
|
556 //!This option setter specifies if the container will cache a pointer to the first
|
Chris@16
|
557 //!non-empty bucket so that begin() is always constant-time.
|
Chris@16
|
558 //!This is specially helpful when we can have containers with a few elements
|
Chris@16
|
559 //!but with big bucket arrays (that is, hashtables with low load factors).
|
Chris@16
|
560 template<bool Enabled>
|
Chris@16
|
561 struct cache_begin
|
Chris@16
|
562 {
|
Chris@16
|
563 /// @cond
|
Chris@16
|
564 template<class Base>
|
Chris@16
|
565 struct pack : Base
|
Chris@16
|
566 {
|
Chris@16
|
567 static const bool cache_begin = Enabled;
|
Chris@16
|
568 };
|
Chris@16
|
569 /// @endcond
|
Chris@16
|
570 };
|
Chris@16
|
571
|
Chris@16
|
572
|
Chris@16
|
573 //!This option setter specifies if the container will compare the hash value
|
Chris@16
|
574 //!before comparing objects. This option can't be specified if store_hash<>
|
Chris@16
|
575 //!is not true.
|
Chris@16
|
576 //!This is specially helpful when we have containers with a high load factor.
|
Chris@16
|
577 //!and the comparison function is much more expensive that comparing already
|
Chris@16
|
578 //!stored hash values.
|
Chris@16
|
579 template<bool Enabled>
|
Chris@16
|
580 struct compare_hash
|
Chris@16
|
581 {
|
Chris@16
|
582 /// @cond
|
Chris@16
|
583 template<class Base>
|
Chris@16
|
584 struct pack : Base
|
Chris@16
|
585 {
|
Chris@16
|
586 static const bool compare_hash = Enabled;
|
Chris@16
|
587 };
|
Chris@16
|
588 /// @endcond
|
Chris@16
|
589 };
|
Chris@16
|
590
|
Chris@16
|
591 //!This option setter specifies if the hash container will use incremental
|
Chris@16
|
592 //!hashing. With incremental hashing the cost of hash table expansion is spread
|
Chris@16
|
593 //!out across each hash table insertion operation, as opposed to be incurred all at once.
|
Chris@16
|
594 //!Therefore linear hashing is well suited for interactive applications or real-time
|
Chris@16
|
595 //!appplications where the worst-case insertion time of non-incremental hash containers
|
Chris@16
|
596 //!(rehashing the whole bucket array) is not admisible.
|
Chris@16
|
597 template<bool Enabled>
|
Chris@16
|
598 struct incremental
|
Chris@16
|
599 {
|
Chris@16
|
600 /// @cond
|
Chris@16
|
601 template<class Base>
|
Chris@16
|
602 struct pack : Base
|
Chris@16
|
603 {
|
Chris@16
|
604 static const bool incremental = Enabled;
|
Chris@16
|
605 };
|
Chris@16
|
606 /// @endcond
|
Chris@16
|
607 };
|
Chris@16
|
608
|
Chris@16
|
609 /// @cond
|
Chris@16
|
610
|
Chris@16
|
611 struct none
|
Chris@16
|
612 {
|
Chris@16
|
613 template<class Base>
|
Chris@16
|
614 struct pack : Base
|
Chris@16
|
615 {};
|
Chris@16
|
616 };
|
Chris@16
|
617
|
Chris@16
|
618 //To-do: pass to variadic templates
|
Chris@16
|
619 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
|
Chris@16
|
620
|
Chris@16
|
621 template<class Prev, class Next>
|
Chris@16
|
622 struct do_pack
|
Chris@16
|
623 {
|
Chris@16
|
624 //Use "pack" member template to pack options
|
Chris@16
|
625 typedef typename Next::template pack<Prev> type;
|
Chris@16
|
626 };
|
Chris@16
|
627
|
Chris@16
|
628 template<class Prev>
|
Chris@16
|
629 struct do_pack<Prev, void>
|
Chris@16
|
630 {
|
Chris@16
|
631 //Avoid packing "void" to shorten template names
|
Chris@16
|
632 typedef Prev type;
|
Chris@16
|
633 };
|
Chris@16
|
634
|
Chris@16
|
635 template
|
Chris@16
|
636 < class DefaultOptions
|
Chris@16
|
637 , class O1 = void
|
Chris@16
|
638 , class O2 = void
|
Chris@16
|
639 , class O3 = void
|
Chris@16
|
640 , class O4 = void
|
Chris@16
|
641 , class O5 = void
|
Chris@16
|
642 , class O6 = void
|
Chris@16
|
643 , class O7 = void
|
Chris@16
|
644 , class O8 = void
|
Chris@16
|
645 , class O9 = void
|
Chris@16
|
646 , class O10 = void
|
Chris@16
|
647 , class O11 = void
|
Chris@16
|
648 >
|
Chris@16
|
649 struct pack_options
|
Chris@16
|
650 {
|
Chris@16
|
651 // join options
|
Chris@16
|
652 typedef
|
Chris@16
|
653 typename do_pack
|
Chris@16
|
654 < typename do_pack
|
Chris@16
|
655 < typename do_pack
|
Chris@16
|
656 < typename do_pack
|
Chris@16
|
657 < typename do_pack
|
Chris@16
|
658 < typename do_pack
|
Chris@16
|
659 < typename do_pack
|
Chris@16
|
660 < typename do_pack
|
Chris@16
|
661 < typename do_pack
|
Chris@16
|
662 < typename do_pack
|
Chris@16
|
663 < typename do_pack
|
Chris@16
|
664 < DefaultOptions
|
Chris@16
|
665 , O1
|
Chris@16
|
666 >::type
|
Chris@16
|
667 , O2
|
Chris@16
|
668 >::type
|
Chris@16
|
669 , O3
|
Chris@16
|
670 >::type
|
Chris@16
|
671 , O4
|
Chris@16
|
672 >::type
|
Chris@16
|
673 , O5
|
Chris@16
|
674 >::type
|
Chris@16
|
675 , O6
|
Chris@16
|
676 >::type
|
Chris@16
|
677 , O7
|
Chris@16
|
678 >::type
|
Chris@16
|
679 , O8
|
Chris@16
|
680 >::type
|
Chris@16
|
681 , O9
|
Chris@16
|
682 >::type
|
Chris@16
|
683 , O10
|
Chris@16
|
684 >::type
|
Chris@16
|
685 , O11
|
Chris@16
|
686 >::type
|
Chris@16
|
687 type;
|
Chris@16
|
688 };
|
Chris@16
|
689 #else
|
Chris@16
|
690
|
Chris@16
|
691 //index_tuple
|
Chris@16
|
692 template<int... Indexes>
|
Chris@16
|
693 struct index_tuple{};
|
Chris@16
|
694
|
Chris@16
|
695 //build_number_seq
|
Chris@16
|
696 template<std::size_t Num, typename Tuple = index_tuple<> >
|
Chris@16
|
697 struct build_number_seq;
|
Chris@16
|
698
|
Chris@16
|
699 template<std::size_t Num, int... Indexes>
|
Chris@16
|
700 struct build_number_seq<Num, index_tuple<Indexes...> >
|
Chris@16
|
701 : build_number_seq<Num - 1, index_tuple<Indexes..., sizeof...(Indexes)> >
|
Chris@16
|
702 {};
|
Chris@16
|
703
|
Chris@16
|
704 template<int... Indexes>
|
Chris@16
|
705 struct build_number_seq<0, index_tuple<Indexes...> >
|
Chris@16
|
706 { typedef index_tuple<Indexes...> type; };
|
Chris@16
|
707
|
Chris@16
|
708 template<class ...Types>
|
Chris@16
|
709 struct typelist
|
Chris@16
|
710 {};
|
Chris@16
|
711
|
Chris@16
|
712 //invert_typelist
|
Chris@16
|
713 template<class T>
|
Chris@16
|
714 struct invert_typelist;
|
Chris@16
|
715
|
Chris@16
|
716 template<int I, typename Tuple>
|
Chris@16
|
717 struct typelist_element;
|
Chris@16
|
718
|
Chris@16
|
719 template<int I, typename Head, typename... Tail>
|
Chris@16
|
720 struct typelist_element<I, typelist<Head, Tail...> >
|
Chris@16
|
721 {
|
Chris@16
|
722 typedef typename typelist_element<I-1, typelist<Tail...> >::type type;
|
Chris@16
|
723 };
|
Chris@16
|
724
|
Chris@16
|
725 template<typename Head, typename... Tail>
|
Chris@16
|
726 struct typelist_element<0, typelist<Head, Tail...> >
|
Chris@16
|
727 {
|
Chris@16
|
728 typedef Head type;
|
Chris@16
|
729 };
|
Chris@16
|
730
|
Chris@16
|
731 template<int ...Ints, class ...Types>
|
Chris@16
|
732 typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>
|
Chris@16
|
733 inverted_typelist(index_tuple<Ints...>, typelist<Types...>)
|
Chris@16
|
734 {
|
Chris@16
|
735 return typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>();
|
Chris@16
|
736 }
|
Chris@16
|
737
|
Chris@16
|
738 //sizeof_typelist
|
Chris@16
|
739 template<class Typelist>
|
Chris@16
|
740 struct sizeof_typelist;
|
Chris@16
|
741
|
Chris@16
|
742 template<class ...Types>
|
Chris@16
|
743 struct sizeof_typelist< typelist<Types...> >
|
Chris@16
|
744 {
|
Chris@16
|
745 static const std::size_t value = sizeof...(Types);
|
Chris@16
|
746 };
|
Chris@16
|
747
|
Chris@16
|
748 //invert_typelist_impl
|
Chris@16
|
749 template<class Typelist, class Indexes>
|
Chris@16
|
750 struct invert_typelist_impl;
|
Chris@16
|
751
|
Chris@16
|
752
|
Chris@16
|
753 template<class Typelist, int ...Ints>
|
Chris@16
|
754 struct invert_typelist_impl< Typelist, index_tuple<Ints...> >
|
Chris@16
|
755 {
|
Chris@16
|
756 static const std::size_t last_idx = sizeof_typelist<Typelist>::value - 1;
|
Chris@16
|
757 typedef typelist
|
Chris@16
|
758 <typename typelist_element<last_idx - Ints, Typelist>::type...> type;
|
Chris@16
|
759 };
|
Chris@16
|
760
|
Chris@16
|
761 template<class Typelist, int Int>
|
Chris@16
|
762 struct invert_typelist_impl< Typelist, index_tuple<Int> >
|
Chris@16
|
763 {
|
Chris@16
|
764 typedef Typelist type;
|
Chris@16
|
765 };
|
Chris@16
|
766
|
Chris@16
|
767 template<class Typelist>
|
Chris@16
|
768 struct invert_typelist_impl< Typelist, index_tuple<> >
|
Chris@16
|
769 {
|
Chris@16
|
770 typedef Typelist type;
|
Chris@16
|
771 };
|
Chris@16
|
772
|
Chris@16
|
773 //invert_typelist
|
Chris@16
|
774 template<class Typelist>
|
Chris@16
|
775 struct invert_typelist;
|
Chris@16
|
776
|
Chris@16
|
777 template<class ...Types>
|
Chris@16
|
778 struct invert_typelist< typelist<Types...> >
|
Chris@16
|
779 {
|
Chris@16
|
780 typedef typelist<Types...> typelist_t;
|
Chris@16
|
781 typedef typename build_number_seq<sizeof...(Types)>::type indexes_t;
|
Chris@16
|
782 typedef typename invert_typelist_impl<typelist_t, indexes_t>::type type;
|
Chris@16
|
783 };
|
Chris@16
|
784
|
Chris@16
|
785 //Do pack
|
Chris@16
|
786 template<class Typelist>
|
Chris@16
|
787 struct do_pack;
|
Chris@16
|
788
|
Chris@16
|
789 template<>
|
Chris@16
|
790 struct do_pack<typelist<> >;
|
Chris@16
|
791
|
Chris@16
|
792 template<class Prev>
|
Chris@16
|
793 struct do_pack<typelist<Prev> >
|
Chris@16
|
794 {
|
Chris@16
|
795 typedef Prev type;
|
Chris@16
|
796 };
|
Chris@16
|
797
|
Chris@16
|
798 template<class Prev, class Last>
|
Chris@16
|
799 struct do_pack<typelist<Prev, Last> >
|
Chris@16
|
800 {
|
Chris@16
|
801 typedef typename Prev::template pack<Last> type;
|
Chris@16
|
802 };
|
Chris@16
|
803
|
Chris@16
|
804 template<class Prev, class ...Others>
|
Chris@16
|
805 struct do_pack<typelist<Prev, Others...> >
|
Chris@16
|
806 {
|
Chris@16
|
807 typedef typename Prev::template pack
|
Chris@16
|
808 <typename do_pack<typelist<Others...> >::type> type;
|
Chris@16
|
809 };
|
Chris@16
|
810
|
Chris@16
|
811
|
Chris@16
|
812 template<class ...Options>
|
Chris@16
|
813 struct pack_options
|
Chris@16
|
814 {
|
Chris@16
|
815 typedef typelist<Options...> typelist_t;
|
Chris@16
|
816 typedef typename invert_typelist<typelist_t>::type inverted_typelist;
|
Chris@16
|
817 typedef typename do_pack<inverted_typelist>::type type;
|
Chris@16
|
818 };
|
Chris@16
|
819
|
Chris@16
|
820 #endif
|
Chris@16
|
821
|
Chris@16
|
822 struct hook_defaults
|
Chris@16
|
823 {
|
Chris@16
|
824 typedef void* void_pointer;
|
Chris@16
|
825 static const link_mode_type link_mode = safe_link;
|
Chris@16
|
826 typedef default_tag tag;
|
Chris@16
|
827 static const bool optimize_size = false;
|
Chris@16
|
828 static const bool store_hash = false;
|
Chris@16
|
829 static const bool linear = false;
|
Chris@16
|
830 static const bool optimize_multikey = false;
|
Chris@16
|
831 };
|
Chris@16
|
832
|
Chris@16
|
833 /// @endcond
|
Chris@16
|
834
|
Chris@16
|
835 } //namespace intrusive {
|
Chris@16
|
836 } //namespace boost {
|
Chris@16
|
837
|
Chris@16
|
838 #include <boost/intrusive/detail/config_end.hpp>
|
Chris@16
|
839
|
Chris@16
|
840 #endif //#ifndef BOOST_INTRUSIVE_OPTIONS_HPP
|