]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/intrusive/include/boost/intrusive/bstree.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / intrusive / include / boost / intrusive / bstree.hpp
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2013-2014
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 #ifndef BOOST_INTRUSIVE_BSTREE_HPP
13 #define BOOST_INTRUSIVE_BSTREE_HPP
14
15 #include <boost/intrusive/detail/config_begin.hpp>
16 #include <boost/intrusive/intrusive_fwd.hpp>
17
18 #include <boost/intrusive/detail/assert.hpp>
19 #include <boost/static_assert.hpp>
20 #include <boost/intrusive/intrusive_fwd.hpp>
21 #include <boost/intrusive/bs_set_hook.hpp>
22 #include <boost/intrusive/detail/tree_node.hpp>
23 #include <boost/intrusive/detail/tree_iterator.hpp>
24 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
25 #include <boost/intrusive/detail/mpl.hpp>
26 #include <boost/intrusive/pointer_traits.hpp>
27 #include <boost/intrusive/detail/is_stateful_value_traits.hpp>
28 #include <boost/intrusive/detail/empty_node_checker.hpp>
29 #include <boost/intrusive/detail/default_header_holder.hpp>
30 #include <boost/intrusive/detail/reverse_iterator.hpp>
31 #include <boost/intrusive/detail/exception_disposer.hpp>
32 #include <boost/intrusive/detail/node_cloner_disposer.hpp>
33 #include <boost/intrusive/detail/key_nodeptr_comp.hpp>
34 #include <boost/intrusive/detail/simple_disposers.hpp>
35 #include <boost/intrusive/detail/size_holder.hpp>
36 #include <boost/intrusive/detail/algo_type.hpp>
37 #include <boost/intrusive/detail/algorithm.hpp>
38 #include <boost/intrusive/detail/tree_value_compare.hpp>
39
40 #include <boost/intrusive/detail/get_value_traits.hpp>
41 #include <boost/intrusive/bstree_algorithms.hpp>
42 #include <boost/intrusive/link_mode.hpp>
43 #include <boost/intrusive/parent_from_member.hpp>
44 #include <boost/move/utility_core.hpp>
45 #include <boost/move/adl_move_swap.hpp>
46
47 #include <boost/intrusive/detail/minimal_pair_header.hpp>
48 #include <cstddef> //size_t...
49 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal_to
50
51 #if defined(BOOST_HAS_PRAGMA_ONCE)
52 # pragma once
53 #endif
54
55 namespace boost {
56 namespace intrusive {
57
58 /// @cond
59
60 struct default_bstree_hook_applier
61 { template <class T> struct apply{ typedef typename T::default_bstree_hook type; }; };
62
63 template<>
64 struct is_default_hook_tag<default_bstree_hook_applier>
65 { static const bool value = true; };
66
67 struct bstree_defaults
68 {
69 typedef default_bstree_hook_applier proto_value_traits;
70 static const bool constant_time_size = true;
71 typedef std::size_t size_type;
72 typedef void compare;
73 typedef void key_of_value;
74 static const bool floating_point = true; //For sgtree
75 typedef void priority; //For treap
76 typedef void header_holder_type;
77 };
78
79 template<class ValueTraits, algo_types AlgoType, typename HeaderHolder>
80 struct bstbase3
81 {
82 typedef ValueTraits value_traits;
83 typedef typename value_traits::node_traits node_traits;
84 typedef typename node_traits::node node_type;
85 typedef typename get_algo<AlgoType, node_traits>::type node_algorithms;
86 typedef typename node_traits::node_ptr node_ptr;
87 typedef typename node_traits::const_node_ptr const_node_ptr;
88 typedef tree_iterator<value_traits, false> iterator;
89 typedef tree_iterator<value_traits, true> const_iterator;
90 typedef boost::intrusive::reverse_iterator<iterator> reverse_iterator;
91 typedef boost::intrusive::reverse_iterator<const_iterator> const_reverse_iterator;
92 typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer;
93 typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer;
94 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type;
95 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
96 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
97 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
98 typedef typename detail::get_header_holder_type
99 < value_traits,HeaderHolder >::type header_holder_type;
100
101 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
102 static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
103 static const bool has_container_from_iterator =
104 detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value;
105
106 struct holder_t : public ValueTraits
107 {
108 BOOST_INTRUSIVE_FORCEINLINE explicit holder_t(const ValueTraits &vtraits)
109 : ValueTraits(vtraits)
110 {}
111 header_holder_type root;
112 } holder;
113
114 static bstbase3 &get_tree_base_from_end_iterator(const const_iterator &end_iterator)
115 {
116 BOOST_STATIC_ASSERT(has_container_from_iterator);
117 node_ptr p = end_iterator.pointed_node();
118 header_holder_type* h = header_holder_type::get_holder(p);
119 holder_t *holder = get_parent_from_member<holder_t, header_holder_type>(h, &holder_t::root);
120 bstbase3 *base = get_parent_from_member<bstbase3, holder_t> (holder, &bstbase3::holder);
121 return *base;
122 }
123
124 BOOST_INTRUSIVE_FORCEINLINE bstbase3(const ValueTraits &vtraits)
125 : holder(vtraits)
126 {
127 node_algorithms::init_header(this->header_ptr());
128 }
129
130 BOOST_INTRUSIVE_FORCEINLINE node_ptr header_ptr()
131 { return holder.root.get_node(); }
132
133 BOOST_INTRUSIVE_FORCEINLINE const_node_ptr header_ptr() const
134 { return holder.root.get_node(); }
135
136 BOOST_INTRUSIVE_FORCEINLINE const value_traits &get_value_traits() const
137 { return this->holder; }
138
139 BOOST_INTRUSIVE_FORCEINLINE value_traits &get_value_traits()
140 { return this->holder; }
141
142 typedef typename boost::intrusive::value_traits_pointers
143 <ValueTraits>::const_value_traits_ptr const_value_traits_ptr;
144
145 BOOST_INTRUSIVE_FORCEINLINE const_value_traits_ptr priv_value_traits_ptr() const
146 { return pointer_traits<const_value_traits_ptr>::pointer_to(this->get_value_traits()); }
147
148 iterator begin()
149 { return iterator(node_algorithms::begin_node(this->header_ptr()), this->priv_value_traits_ptr()); }
150
151 BOOST_INTRUSIVE_FORCEINLINE const_iterator begin() const
152 { return cbegin(); }
153
154 const_iterator cbegin() const
155 { return const_iterator(node_algorithms::begin_node(this->header_ptr()), this->priv_value_traits_ptr()); }
156
157 iterator end()
158 { return iterator(node_algorithms::end_node(this->header_ptr()), this->priv_value_traits_ptr()); }
159
160 BOOST_INTRUSIVE_FORCEINLINE const_iterator end() const
161 { return cend(); }
162
163 BOOST_INTRUSIVE_FORCEINLINE const_iterator cend() const
164 { return const_iterator(node_algorithms::end_node(this->header_ptr()), this->priv_value_traits_ptr()); }
165
166 BOOST_INTRUSIVE_FORCEINLINE iterator root()
167 { return iterator(node_algorithms::root_node(this->header_ptr()), this->priv_value_traits_ptr()); }
168
169 BOOST_INTRUSIVE_FORCEINLINE const_iterator root() const
170 { return croot(); }
171
172 BOOST_INTRUSIVE_FORCEINLINE const_iterator croot() const
173 { return const_iterator(node_algorithms::root_node(this->header_ptr()), this->priv_value_traits_ptr()); }
174
175 BOOST_INTRUSIVE_FORCEINLINE reverse_iterator rbegin()
176 { return reverse_iterator(end()); }
177
178 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator rbegin() const
179 { return const_reverse_iterator(end()); }
180
181 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator crbegin() const
182 { return const_reverse_iterator(end()); }
183
184 BOOST_INTRUSIVE_FORCEINLINE reverse_iterator rend()
185 { return reverse_iterator(begin()); }
186
187 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator rend() const
188 { return const_reverse_iterator(begin()); }
189
190 BOOST_INTRUSIVE_FORCEINLINE const_reverse_iterator crend() const
191 { return const_reverse_iterator(begin()); }
192
193 void replace_node(iterator replace_this, reference with_this)
194 {
195 node_algorithms::replace_node( get_value_traits().to_node_ptr(*replace_this)
196 , this->header_ptr()
197 , get_value_traits().to_node_ptr(with_this));
198 if(safemode_or_autounlink)
199 node_algorithms::init(replace_this.pointed_node());
200 }
201
202 BOOST_INTRUSIVE_FORCEINLINE void rebalance()
203 { node_algorithms::rebalance(this->header_ptr()); }
204
205 iterator rebalance_subtree(iterator root)
206 { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this->priv_value_traits_ptr()); }
207
208 static iterator s_iterator_to(reference value)
209 {
210 BOOST_STATIC_ASSERT((!stateful_value_traits));
211 return iterator (value_traits::to_node_ptr(value), const_value_traits_ptr());
212 }
213
214 static const_iterator s_iterator_to(const_reference value)
215 {
216 BOOST_STATIC_ASSERT((!stateful_value_traits));
217 return const_iterator (value_traits::to_node_ptr(*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value))), const_value_traits_ptr());
218 }
219
220 iterator iterator_to(reference value)
221 { return iterator (this->get_value_traits().to_node_ptr(value), this->priv_value_traits_ptr()); }
222
223 const_iterator iterator_to(const_reference value) const
224 { return const_iterator (this->get_value_traits().to_node_ptr(*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value))), this->priv_value_traits_ptr()); }
225
226 BOOST_INTRUSIVE_FORCEINLINE static void init_node(reference value)
227 { node_algorithms::init(value_traits::to_node_ptr(value)); }
228
229 };
230
231 template<class Less, class T>
232 struct get_compare
233 {
234 typedef Less type;
235 };
236
237 template<class T>
238 struct get_compare<void, T>
239 {
240 typedef ::std::less<T> type;
241 };
242
243 template<class KeyOfValue, class T>
244 struct get_key_of_value
245 {
246 typedef KeyOfValue type;
247 };
248
249 template<class T>
250 struct get_key_of_value<void, T>
251 {
252 typedef ::boost::intrusive::detail::identity<T> type;
253 };
254
255 template<class ValuePtr, class VoidOrKeyOfValue, class VoidOrKeyComp>
256 struct bst_key_types
257 {
258 typedef typename pointer_element<ValuePtr>::type value_type;
259 typedef typename get_key_of_value
260 < VoidOrKeyOfValue, value_type>::type key_of_value;
261 typedef typename key_of_value::type key_type;
262 typedef typename get_compare< VoidOrKeyComp
263 , key_type
264 >::type key_compare;
265 typedef tree_value_compare
266 <ValuePtr, key_compare, key_of_value> value_compare;
267 };
268
269 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, algo_types AlgoType, typename HeaderHolder>
270 struct bstbase2
271 //Put the (possibly empty) functor in the first position to get EBO in MSVC
272 //Use public inheritance to avoid MSVC bugs with closures
273 : public detail::ebo_functor_holder
274 < typename bst_key_types
275 < typename ValueTraits::pointer
276 , VoidOrKeyOfValue
277 , VoidOrKeyComp
278
279 >::value_compare
280 >
281 , public bstbase3<ValueTraits, AlgoType, HeaderHolder>
282 {
283 typedef bstbase3<ValueTraits, AlgoType, HeaderHolder> treeheader_t;
284 typedef bst_key_types< typename ValueTraits::pointer
285 , VoidOrKeyOfValue
286 , VoidOrKeyComp> key_types;
287 typedef typename treeheader_t::value_traits value_traits;
288 typedef typename treeheader_t::node_algorithms node_algorithms;
289 typedef typename ValueTraits::value_type value_type;
290 typedef typename key_types::key_type key_type;
291 typedef typename key_types::key_of_value key_of_value;
292 typedef typename key_types::key_compare key_compare;
293 typedef typename key_types::value_compare value_compare;
294 typedef typename treeheader_t::iterator iterator;
295 typedef typename treeheader_t::const_iterator const_iterator;
296 typedef typename treeheader_t::node_ptr node_ptr;
297 typedef typename treeheader_t::const_node_ptr const_node_ptr;
298
299 bstbase2(const key_compare &comp, const ValueTraits &vtraits)
300 : detail::ebo_functor_holder<value_compare>(value_compare(comp)), treeheader_t(vtraits)
301 {}
302
303 const value_compare &comp() const
304 { return this->get(); }
305
306 value_compare &comp()
307 { return this->get(); }
308
309 typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer;
310 typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer;
311 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
312 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
313 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
314 typedef typename node_algorithms::insert_commit_data insert_commit_data;
315
316 BOOST_INTRUSIVE_FORCEINLINE value_compare value_comp() const
317 { return this->comp(); }
318
319 BOOST_INTRUSIVE_FORCEINLINE key_compare key_comp() const
320 { return this->comp().key_comp(); }
321
322 //lower_bound
323 BOOST_INTRUSIVE_FORCEINLINE iterator lower_bound(const key_type &key)
324 { return this->lower_bound(key, this->key_comp()); }
325
326 BOOST_INTRUSIVE_FORCEINLINE const_iterator lower_bound(const key_type &key) const
327 { return this->lower_bound(key, this->key_comp()); }
328
329 template<class KeyType, class KeyTypeKeyCompare>
330 iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp)
331 {
332 return iterator(node_algorithms::lower_bound
333 (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
334 }
335
336 template<class KeyType, class KeyTypeKeyCompare>
337 const_iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp) const
338 {
339 return const_iterator(node_algorithms::lower_bound
340 (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
341 }
342
343 //upper_bound
344 BOOST_INTRUSIVE_FORCEINLINE iterator upper_bound(const key_type &key)
345 { return this->upper_bound(key, this->key_comp()); }
346
347 template<class KeyType, class KeyTypeKeyCompare>
348 iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp)
349 {
350 return iterator(node_algorithms::upper_bound
351 (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
352 }
353
354 BOOST_INTRUSIVE_FORCEINLINE const_iterator upper_bound(const key_type &key) const
355 { return this->upper_bound(key, this->key_comp()); }
356
357 template<class KeyType, class KeyTypeKeyCompare>
358 const_iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp) const
359 {
360 return const_iterator(node_algorithms::upper_bound
361 (this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
362 }
363
364 template<class KeyTypeKeyCompare>
365 struct key_node_comp_ret
366 { typedef detail::key_nodeptr_comp<KeyTypeKeyCompare, value_traits, key_of_value> type; };
367
368 template<class KeyTypeKeyCompare>
369 BOOST_INTRUSIVE_FORCEINLINE typename key_node_comp_ret<KeyTypeKeyCompare>::type key_node_comp(KeyTypeKeyCompare comp) const
370 {
371 return detail::key_nodeptr_comp<KeyTypeKeyCompare, value_traits, key_of_value>(comp, &this->get_value_traits());
372 }
373
374 //find
375 BOOST_INTRUSIVE_FORCEINLINE iterator find(const key_type &key)
376 { return this->find(key, this->key_comp()); }
377
378 template<class KeyType, class KeyTypeKeyCompare>
379 iterator find(const KeyType &key, KeyTypeKeyCompare comp)
380 {
381 return iterator
382 (node_algorithms::find(this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
383 }
384
385 BOOST_INTRUSIVE_FORCEINLINE const_iterator find(const key_type &key) const
386 { return this->find(key, this->key_comp()); }
387
388 template<class KeyType, class KeyTypeKeyCompare>
389 const_iterator find(const KeyType &key, KeyTypeKeyCompare comp) const
390 {
391 return const_iterator
392 (node_algorithms::find(this->header_ptr(), key, this->key_node_comp(comp)), this->priv_value_traits_ptr());
393 }
394
395 //equal_range
396 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator,iterator> equal_range(const key_type &key)
397 { return this->equal_range(key, this->key_comp()); }
398
399 template<class KeyType, class KeyTypeKeyCompare>
400 std::pair<iterator,iterator> equal_range(const KeyType &key, KeyTypeKeyCompare comp)
401 {
402 std::pair<node_ptr, node_ptr> ret
403 (node_algorithms::equal_range(this->header_ptr(), key, this->key_node_comp(comp)));
404 return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr())
405 , iterator(ret.second, this->priv_value_traits_ptr()));
406 }
407
408 BOOST_INTRUSIVE_FORCEINLINE std::pair<const_iterator, const_iterator>
409 equal_range(const key_type &key) const
410 { return this->equal_range(key, this->key_comp()); }
411
412 template<class KeyType, class KeyTypeKeyCompare>
413 std::pair<const_iterator, const_iterator>
414 equal_range(const KeyType &key, KeyTypeKeyCompare comp) const
415 {
416 std::pair<node_ptr, node_ptr> ret
417 (node_algorithms::equal_range(this->header_ptr(), key, this->key_node_comp(comp)));
418 return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr())
419 , const_iterator(ret.second, this->priv_value_traits_ptr()));
420 }
421
422 //lower_bound_range
423 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator,iterator> lower_bound_range(const key_type &key)
424 { return this->lower_bound_range(key, this->key_comp()); }
425
426 template<class KeyType, class KeyTypeKeyCompare>
427 std::pair<iterator,iterator> lower_bound_range(const KeyType &key, KeyTypeKeyCompare comp)
428 {
429 std::pair<node_ptr, node_ptr> ret
430 (node_algorithms::lower_bound_range(this->header_ptr(), key, this->key_node_comp(comp)));
431 return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr())
432 , iterator(ret.second, this->priv_value_traits_ptr()));
433 }
434
435 BOOST_INTRUSIVE_FORCEINLINE std::pair<const_iterator, const_iterator>
436 lower_bound_range(const key_type &key) const
437 { return this->lower_bound_range(key, this->key_comp()); }
438
439 template<class KeyType, class KeyTypeKeyCompare>
440 std::pair<const_iterator, const_iterator>
441 lower_bound_range(const KeyType &key, KeyTypeKeyCompare comp) const
442 {
443 std::pair<node_ptr, node_ptr> ret
444 (node_algorithms::lower_bound_range(this->header_ptr(), key, this->key_node_comp(comp)));
445 return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr())
446 , const_iterator(ret.second, this->priv_value_traits_ptr()));
447 }
448
449 //bounded_range
450 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator,iterator> bounded_range
451 (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed)
452 { return this->bounded_range(lower_key, upper_key, this->key_comp(), left_closed, right_closed); }
453
454 template<class KeyType, class KeyTypeKeyCompare>
455 std::pair<iterator,iterator> bounded_range
456 (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed)
457 {
458 std::pair<node_ptr, node_ptr> ret
459 (node_algorithms::bounded_range
460 (this->header_ptr(), lower_key, upper_key, this->key_node_comp(comp), left_closed, right_closed));
461 return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr())
462 , iterator(ret.second, this->priv_value_traits_ptr()));
463 }
464
465 BOOST_INTRUSIVE_FORCEINLINE std::pair<const_iterator,const_iterator> bounded_range
466 (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const
467 { return this->bounded_range(lower_key, upper_key, this->key_comp(), left_closed, right_closed); }
468
469 template<class KeyType, class KeyTypeKeyCompare>
470 std::pair<const_iterator,const_iterator> bounded_range
471 (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const
472 {
473 std::pair<node_ptr, node_ptr> ret
474 (node_algorithms::bounded_range
475 (this->header_ptr(), lower_key, upper_key, this->key_node_comp(comp), left_closed, right_closed));
476 return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr())
477 , const_iterator(ret.second, this->priv_value_traits_ptr()));
478 }
479
480 //insert_unique_check
481 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator, bool> insert_unique_check
482 (const key_type &key, insert_commit_data &commit_data)
483 { return this->insert_unique_check(key, this->key_comp(), commit_data); }
484
485 BOOST_INTRUSIVE_FORCEINLINE std::pair<iterator, bool> insert_unique_check
486 (const_iterator hint, const key_type &key, insert_commit_data &commit_data)
487 { return this->insert_unique_check(hint, key, this->key_comp(), commit_data); }
488
489 template<class KeyType, class KeyTypeKeyCompare>
490 BOOST_INTRUSIVE_DOC1ST(std::pair<iterator BOOST_INTRUSIVE_I bool>
491 , typename detail::disable_if_convertible
492 <KeyType BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I
493 std::pair<iterator BOOST_INTRUSIVE_I bool> >::type)
494 insert_unique_check
495 (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data)
496 {
497 std::pair<node_ptr, bool> ret =
498 (node_algorithms::insert_unique_check
499 (this->header_ptr(), key, this->key_node_comp(comp), commit_data));
500 return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
501 }
502
503 template<class KeyType, class KeyTypeKeyCompare>
504 std::pair<iterator, bool> insert_unique_check
505 (const_iterator hint, const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data)
506 {
507 std::pair<node_ptr, bool> ret =
508 (node_algorithms::insert_unique_check
509 (this->header_ptr(), hint.pointed_node(), key, this->key_node_comp(comp), commit_data));
510 return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second);
511 }
512 };
513
514 //Due to MSVC's EBO implementation, to save space and maintain the ABI, we must put the non-empty size member
515 //in the first position, but if size is not going to be stored then we'll use an specialization
516 //that doesn't inherit from size_holder
517 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, bool ConstantTimeSize, class SizeType, algo_types AlgoType, typename HeaderHolder>
518 struct bstbase_hack
519 : public detail::size_holder<ConstantTimeSize, SizeType>
520 , public bstbase2 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder>
521 {
522 typedef bstbase2< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder> base_type;
523 typedef typename base_type::key_compare key_compare;
524 typedef typename base_type::value_compare value_compare;
525 typedef SizeType size_type;
526 typedef typename base_type::node_traits node_traits;
527 typedef typename get_algo
528 <AlgoType, node_traits>::type algo_type;
529
530 BOOST_INTRUSIVE_FORCEINLINE bstbase_hack(const key_compare & comp, const ValueTraits &vtraits)
531 : base_type(comp, vtraits)
532 {
533 this->sz_traits().set_size(size_type(0));
534 }
535
536 typedef detail::size_holder<ConstantTimeSize, SizeType> size_traits;
537
538 BOOST_INTRUSIVE_FORCEINLINE size_traits &sz_traits()
539 { return static_cast<size_traits &>(*this); }
540
541 BOOST_INTRUSIVE_FORCEINLINE const size_traits &sz_traits() const
542 { return static_cast<const size_traits &>(*this); }
543 };
544
545 //Specialization for ConstantTimeSize == false
546 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, algo_types AlgoType, typename HeaderHolder>
547 struct bstbase_hack<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, false, SizeType, AlgoType, HeaderHolder>
548 : public bstbase2 < ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder>
549 {
550 typedef bstbase2< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, AlgoType, HeaderHolder> base_type;
551 typedef typename base_type::value_compare value_compare;
552 typedef typename base_type::key_compare key_compare;
553 BOOST_INTRUSIVE_FORCEINLINE bstbase_hack(const key_compare & comp, const ValueTraits &vtraits)
554 : base_type(comp, vtraits)
555 {}
556
557 typedef detail::size_holder<false, SizeType> size_traits;
558
559 BOOST_INTRUSIVE_FORCEINLINE size_traits sz_traits() const
560 { return size_traits(); }
561 };
562
563 //This class will
564 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, bool ConstantTimeSize, class SizeType, algo_types AlgoType, typename HeaderHolder>
565 struct bstbase
566 : public bstbase_hack< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder>
567 {
568 typedef bstbase_hack< ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> base_type;
569 typedef ValueTraits value_traits;
570 typedef typename base_type::value_compare value_compare;
571 typedef typename base_type::key_compare key_compare;
572 typedef typename base_type::const_reference const_reference;
573 typedef typename base_type::reference reference;
574 typedef typename base_type::iterator iterator;
575 typedef typename base_type::const_iterator const_iterator;
576 typedef typename base_type::node_traits node_traits;
577 typedef typename get_algo
578 <AlgoType, node_traits>::type node_algorithms;
579 typedef SizeType size_type;
580
581 BOOST_INTRUSIVE_FORCEINLINE bstbase(const key_compare & comp, const ValueTraits &vtraits)
582 : base_type(comp, vtraits)
583 {}
584
585 //Detach all inserted nodes. This will add exception safety to bstree_impl
586 //constructors inserting elements.
587 ~bstbase()
588 {
589 if(is_safe_autounlink<value_traits::link_mode>::value){
590 node_algorithms::clear_and_dispose
591 ( this->header_ptr()
592 , detail::node_disposer<detail::null_disposer, value_traits, AlgoType>
593 (detail::null_disposer(), &this->get_value_traits()));
594 node_algorithms::init(this->header_ptr());
595 }
596 }
597 };
598
599
600 /// @endcond
601
602 //! The class template bstree is an unbalanced intrusive binary search tree
603 //! container. The no-throw guarantee holds only, if the key_compare object
604 //! doesn't throw.
605 //!
606 //! The complexity guarantees only hold if the tree is balanced, logarithmic
607 //! complexity would increase to linear if the tree is totally unbalanced.
608 //!
609 //! The template parameter \c T is the type to be managed by the container.
610 //! The user can specify additional options and if no options are provided
611 //! default options are used.
612 //!
613 //! The container supports the following options:
614 //! \c base_hook<>/member_hook<>/value_traits<>,
615 //! \c constant_time_size<>, \c size_type<> and
616 //! \c compare<>.
617 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
618 template<class T, class ...Options>
619 #else
620 template<class ValueTraits, class VoidOrKeyOfValue, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder>
621 #endif
622 class bstree_impl
623 : public bstbase<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder>
624 {
625 public:
626 /// @cond
627 typedef bstbase<ValueTraits, VoidOrKeyOfValue, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> data_type;
628 typedef tree_iterator<ValueTraits, false> iterator_type;
629 typedef tree_iterator<ValueTraits, true> const_iterator_type;
630 /// @endcond
631
632 typedef BOOST_INTRUSIVE_IMPDEF(ValueTraits) value_traits;
633 typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer;
634 typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer;
635 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type;
636 typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::key_type) key_type;
637 typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::key_of_value) key_of_value;
638 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference;
639 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference;
640 typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type;
641 typedef BOOST_INTRUSIVE_IMPDEF(SizeType) size_type;
642 typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::value_compare) value_compare;
643 typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::key_compare) key_compare;
644 typedef BOOST_INTRUSIVE_IMPDEF(iterator_type) iterator;
645 typedef BOOST_INTRUSIVE_IMPDEF(const_iterator_type) const_iterator;
646 typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::reverse_iterator<iterator>) reverse_iterator;
647 typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::reverse_iterator<const_iterator>) const_reverse_iterator;
648 typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::node_traits) node_traits;
649 typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node) node;
650 typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node_ptr) node_ptr;
651 typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::const_node_ptr) const_node_ptr;
652 /// @cond
653 typedef typename get_algo<AlgoType, node_traits>::type algo_type;
654 /// @endcond
655 typedef BOOST_INTRUSIVE_IMPDEF(algo_type) node_algorithms;
656
657 static const bool constant_time_size = ConstantTimeSize;
658 static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value;
659 /// @cond
660 private:
661
662 //noncopyable
663 BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree_impl)
664
665 static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value;
666
667 //Constant-time size is incompatible with auto-unlink hooks!
668 BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink)));
669
670
671 protected:
672
673
674 /// @endcond
675
676 public:
677
678 typedef typename node_algorithms::insert_commit_data insert_commit_data;
679
680 //! <b>Effects</b>: Constructs an empty container.
681 //!
682 //! <b>Complexity</b>: Constant.
683 //!
684 //! <b>Throws</b>: If value_traits::node_traits::node
685 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
686 //! or the copy constructor of the key_compare object throws. Basic guarantee.
687 bstree_impl()
688 : data_type(key_compare(), value_traits())
689 {}
690
691 //! <b>Effects</b>: Constructs an empty container with given comparison and traits.
692 //!
693 //! <b>Complexity</b>: Constant.
694 //!
695 //! <b>Throws</b>: If value_traits::node_traits::node
696 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
697 //! or the copy constructor of the key_compare object throws. Basic guarantee.
698 explicit bstree_impl( const key_compare &cmp, const value_traits &v_traits = value_traits())
699 : data_type(cmp, v_traits)
700 {}
701
702 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
703 //! cmp must be a comparison function that induces a strict weak ordering.
704 //!
705 //! <b>Effects</b>: Constructs an empty container and inserts elements from
706 //! [b, e).
707 //!
708 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
709 //! comp and otherwise N * log N, where N is the distance between first and last.
710 //!
711 //! <b>Throws</b>: If value_traits::node_traits::node
712 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
713 //! or the copy constructor/operator() of the key_compare object throws. Basic guarantee.
714 template<class Iterator>
715 bstree_impl( bool unique, Iterator b, Iterator e
716 , const key_compare &cmp = key_compare()
717 , const value_traits &v_traits = value_traits())
718 : data_type(cmp, v_traits)
719 {
720 //bstbase releases elements in case of exceptions
721 if(unique)
722 this->insert_unique(b, e);
723 else
724 this->insert_equal(b, e);
725 }
726
727 //! <b>Effects</b>: to-do
728 //!
729 bstree_impl(BOOST_RV_REF(bstree_impl) x)
730 : data_type(::boost::move(x.comp()), ::boost::move(x.get_value_traits()))
731 {
732 this->swap(x);
733 }
734
735 //! <b>Effects</b>: to-do
736 //!
737 BOOST_INTRUSIVE_FORCEINLINE bstree_impl& operator=(BOOST_RV_REF(bstree_impl) x)
738 { this->swap(x); return *this; }
739
740 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
741 //! <b>Effects</b>: Detaches all elements from this. The objects in the set
742 //! are not deleted (i.e. no destructors are called), but the nodes according to
743 //! the value_traits template parameter are reinitialized and thus can be reused.
744 //!
745 //! <b>Complexity</b>: Linear to elements contained in *this.
746 //!
747 //! <b>Throws</b>: Nothing.
748 ~bstree_impl()
749 {}
750
751 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the container.
752 //!
753 //! <b>Complexity</b>: Constant.
754 //!
755 //! <b>Throws</b>: Nothing.
756 iterator begin();
757
758 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the container.
759 //!
760 //! <b>Complexity</b>: Constant.
761 //!
762 //! <b>Throws</b>: Nothing.
763 const_iterator begin() const;
764
765 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the container.
766 //!
767 //! <b>Complexity</b>: Constant.
768 //!
769 //! <b>Throws</b>: Nothing.
770 const_iterator cbegin() const;
771
772 //! <b>Effects</b>: Returns an iterator pointing to the end of the container.
773 //!
774 //! <b>Complexity</b>: Constant.
775 //!
776 //! <b>Throws</b>: Nothing.
777 iterator end();
778
779 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the container.
780 //!
781 //! <b>Complexity</b>: Constant.
782 //!
783 //! <b>Throws</b>: Nothing.
784 const_iterator end() const;
785
786 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the container.
787 //!
788 //! <b>Complexity</b>: Constant.
789 //!
790 //! <b>Throws</b>: Nothing.
791 const_iterator cend() const;
792
793 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
794 //! reversed container.
795 //!
796 //! <b>Complexity</b>: Constant.
797 //!
798 //! <b>Throws</b>: Nothing.
799 reverse_iterator rbegin();
800
801 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
802 //! of the reversed container.
803 //!
804 //! <b>Complexity</b>: Constant.
805 //!
806 //! <b>Throws</b>: Nothing.
807 const_reverse_iterator rbegin() const;
808
809 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
810 //! of the reversed container.
811 //!
812 //! <b>Complexity</b>: Constant.
813 //!
814 //! <b>Throws</b>: Nothing.
815 const_reverse_iterator crbegin() const;
816
817 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
818 //! of the reversed container.
819 //!
820 //! <b>Complexity</b>: Constant.
821 //!
822 //! <b>Throws</b>: Nothing.
823 reverse_iterator rend();
824
825 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
826 //! of the reversed container.
827 //!
828 //! <b>Complexity</b>: Constant.
829 //!
830 //! <b>Throws</b>: Nothing.
831 const_reverse_iterator rend() const;
832
833 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
834 //! of the reversed container.
835 //!
836 //! <b>Complexity</b>: Constant.
837 //!
838 //! <b>Throws</b>: Nothing.
839 const_reverse_iterator crend() const;
840
841 //! <b>Effects</b>: Returns a iterator pointing to the root node of the container or end() if not present.
842 //!
843 //! <b>Complexity</b>: Constant.
844 //!
845 //! <b>Throws</b>: Nothing.
846 iterator root();
847
848 //! <b>Effects</b>: Returns a const_iterator pointing to the root node of the container or cend() if not present.
849 //!
850 //! <b>Complexity</b>: Constant.
851 //!
852 //! <b>Throws</b>: Nothing.
853 const_iterator root() const;
854
855 //! <b>Effects</b>: Returns a const_iterator pointing to the root node of the container or cend() if not present.
856 //!
857 //! <b>Complexity</b>: Constant.
858 //!
859 //! <b>Throws</b>: Nothing.
860 const_iterator croot() const;
861
862 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
863
864 //! <b>Precondition</b>: end_iterator must be a valid end iterator
865 //! of the container.
866 //!
867 //! <b>Effects</b>: Returns a const reference to the container associated to the end iterator
868 //!
869 //! <b>Throws</b>: Nothing.
870 //!
871 //! <b>Complexity</b>: Constant.
872 static bstree_impl &container_from_end_iterator(iterator end_iterator)
873 {
874 return static_cast<bstree_impl&>
875 (data_type::get_tree_base_from_end_iterator(end_iterator));
876 }
877
878 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
879 //! of the container.
880 //!
881 //! <b>Effects</b>: Returns a const reference to the container associated to the iterator
882 //!
883 //! <b>Throws</b>: Nothing.
884 //!
885 //! <b>Complexity</b>: Constant.
886 static const bstree_impl &container_from_end_iterator(const_iterator end_iterator)
887 {
888 return static_cast<bstree_impl&>
889 (data_type::get_tree_base_from_end_iterator(end_iterator));
890 }
891
892 //! <b>Precondition</b>: it must be a valid iterator
893 //! of the container.
894 //!
895 //! <b>Effects</b>: Returns a const reference to the container associated to the iterator
896 //!
897 //! <b>Throws</b>: Nothing.
898 //!
899 //! <b>Complexity</b>: Logarithmic.
900 static bstree_impl &container_from_iterator(iterator it)
901 { return container_from_end_iterator(it.end_iterator_from_it()); }
902
903 //! <b>Precondition</b>: it must be a valid end const_iterator
904 //! of container.
905 //!
906 //! <b>Effects</b>: Returns a const reference to the container associated to the end iterator
907 //!
908 //! <b>Throws</b>: Nothing.
909 //!
910 //! <b>Complexity</b>: Logarithmic.
911 static const bstree_impl &container_from_iterator(const_iterator it)
912 { return container_from_end_iterator(it.end_iterator_from_it()); }
913
914 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
915
916 //! <b>Effects</b>: Returns the key_compare object used by the container.
917 //!
918 //! <b>Complexity</b>: Constant.
919 //!
920 //! <b>Throws</b>: If key_compare copy-constructor throws.
921 key_compare key_comp() const;
922
923 //! <b>Effects</b>: Returns the value_compare object used by the container.
924 //!
925 //! <b>Complexity</b>: Constant.
926 //!
927 //! <b>Throws</b>: If value_compare copy-constructor throws.
928 value_compare value_comp() const;
929
930 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
931
932 //! <b>Effects</b>: Returns true if the container is empty.
933 //!
934 //! <b>Complexity</b>: Constant.
935 //!
936 //! <b>Throws</b>: Nothing.
937 bool empty() const
938 {
939 if(ConstantTimeSize){
940 return !this->data_type::sz_traits().get_size();
941 }
942 else{
943 return algo_type::unique(this->header_ptr());
944 }
945 }
946
947 //! <b>Effects</b>: Returns the number of elements stored in the container.
948 //!
949 //! <b>Complexity</b>: Linear to elements contained in *this
950 //! if constant-time size option is disabled. Constant time otherwise.
951 //!
952 //! <b>Throws</b>: Nothing.
953 size_type size() const
954 {
955 if(constant_time_size)
956 return this->sz_traits().get_size();
957 else{
958 return (size_type)node_algorithms::size(this->header_ptr());
959 }
960 }
961
962 //! <b>Effects</b>: Swaps the contents of two containers.
963 //!
964 //! <b>Complexity</b>: Constant.
965 //!
966 //! <b>Throws</b>: If the comparison functor's swap call throws.
967 void swap(bstree_impl& other)
968 {
969 //This can throw
970 ::boost::adl_move_swap(this->comp(), this->comp());
971 //These can't throw
972 node_algorithms::swap_tree(this->header_ptr(), node_ptr(other.header_ptr()));
973 this->sz_traits().swap(other.sz_traits());
974 }
975
976 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
977 //! Cloner should yield to nodes equivalent to the original nodes.
978 //!
979 //! <b>Effects</b>: Erases all the elements from *this
980 //! calling Disposer::operator()(pointer), clones all the
981 //! elements from src calling Cloner::operator()(const_reference )
982 //! and inserts them on *this. Copies the predicate from the source container.
983 //!
984 //! If cloner throws, all cloned elements are unlinked and disposed
985 //! calling Disposer::operator()(pointer).
986 //!
987 //! <b>Complexity</b>: Linear to erased plus inserted elements.
988 //!
989 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
990 template <class Cloner, class Disposer>
991 void clone_from(const bstree_impl &src, Cloner cloner, Disposer disposer)
992 {
993 this->clear_and_dispose(disposer);
994 if(!src.empty()){
995 detail::exception_disposer<bstree_impl, Disposer>
996 rollback(*this, disposer);
997 node_algorithms::clone
998 (src.header_ptr()
999 ,this->header_ptr()
1000 ,detail::node_cloner <Cloner, value_traits, AlgoType>(cloner, &this->get_value_traits())
1001 ,detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits()));
1002 this->sz_traits().set_size(src.sz_traits().get_size());
1003 this->comp() = src.comp();
1004 rollback.release();
1005 }
1006 }
1007
1008 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1009 //! Cloner should yield to nodes equivalent to the original nodes.
1010 //!
1011 //! <b>Effects</b>: Erases all the elements from *this
1012 //! calling Disposer::operator()(pointer), clones all the
1013 //! elements from src calling Cloner::operator()(reference)
1014 //! and inserts them on *this. Copies the predicate from the source container.
1015 //!
1016 //! If cloner throws, all cloned elements are unlinked and disposed
1017 //! calling Disposer::operator()(pointer).
1018 //!
1019 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1020 //!
1021 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1022 //!
1023 //! <b>Note</b>: This version can modify the source container, useful to implement
1024 //! move semantics.
1025 template <class Cloner, class Disposer>
1026 void clone_from(BOOST_RV_REF(bstree_impl) src, Cloner cloner, Disposer disposer)
1027 {
1028 this->clear_and_dispose(disposer);
1029 if(!src.empty()){
1030 detail::exception_disposer<bstree_impl, Disposer>
1031 rollback(*this, disposer);
1032 node_algorithms::clone
1033 (src.header_ptr()
1034 ,this->header_ptr()
1035 ,detail::node_cloner <Cloner, value_traits, AlgoType, false>(cloner, &this->get_value_traits())
1036 ,detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits()));
1037 this->sz_traits().set_size(src.sz_traits().get_size());
1038 this->comp() = src.comp();
1039 rollback.release();
1040 }
1041 }
1042
1043 //! <b>Requires</b>: value must be an lvalue
1044 //!
1045 //! <b>Effects</b>: Inserts value into the container before the upper bound.
1046 //!
1047 //! <b>Complexity</b>: Average complexity for insert element is at
1048 //! most logarithmic.
1049 //!
1050 //! <b>Throws</b>: If the internal key_compare ordering function throws. Strong guarantee.
1051 //!
1052 //! <b>Note</b>: Does not affect the validity of iterators and references.
1053 //! No copy-constructors are called.
1054 iterator insert_equal(reference value)
1055 {
1056 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
1057 if(safemode_or_autounlink)
1058 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
1059 iterator ret(node_algorithms::insert_equal_upper_bound
1060 (this->header_ptr(), to_insert, this->key_node_comp(this->key_comp())), this->priv_value_traits_ptr());
1061 this->sz_traits().increment();
1062 return ret;
1063 }
1064
1065 //! <b>Requires</b>: value must be an lvalue, and "hint" must be
1066 //! a valid iterator.
1067 //!
1068 //! <b>Effects</b>: Inserts x into the container, using "hint" as a hint to
1069 //! where it will be inserted. If "hint" is the upper_bound
1070 //! the insertion takes constant time (two comparisons in the worst case)
1071 //!
1072 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1073 //! constant time if t is inserted immediately before hint.
1074 //!
1075 //! <b>Throws</b>: If the internal key_compare ordering function throws. Strong guarantee.
1076 //!
1077 //! <b>Note</b>: Does not affect the validity of iterators and references.
1078 //! No copy-constructors are called.
1079 iterator insert_equal(const_iterator hint, reference value)
1080 {
1081 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
1082 if(safemode_or_autounlink)
1083 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
1084 iterator ret(node_algorithms::insert_equal
1085 (this->header_ptr(), hint.pointed_node(), to_insert, this->key_node_comp(this->key_comp())), this->priv_value_traits_ptr());
1086 this->sz_traits().increment();
1087 return ret;
1088 }
1089
1090 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1091 //! of type value_type.
1092 //!
1093 //! <b>Effects</b>: Inserts a each element of a range into the container
1094 //! before the upper bound of the key of each element.
1095 //!
1096 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1097 //! size of the range. However, it is linear in N if the range is already sorted
1098 //! by value_comp().
1099 //!
1100 //! <b>Throws</b>: Nothing.
1101 //!
1102 //! <b>Note</b>: Does not affect the validity of iterators and references.
1103 //! No copy-constructors are called.
1104 template<class Iterator>
1105 void insert_equal(Iterator b, Iterator e)
1106 {
1107 iterator iend(this->end());
1108 for (; b != e; ++b)
1109 this->insert_equal(iend, *b);
1110 }
1111
1112 //! <b>Requires</b>: value must be an lvalue
1113 //!
1114 //! <b>Effects</b>: Inserts value into the container if the value
1115 //! is not already present.
1116 //!
1117 //! <b>Complexity</b>: Average complexity for insert element is at
1118 //! most logarithmic.
1119 //!
1120 //! <b>Throws</b>: Nothing.
1121 //!
1122 //! <b>Note</b>: Does not affect the validity of iterators and references.
1123 //! No copy-constructors are called.
1124 std::pair<iterator, bool> insert_unique(reference value)
1125 {
1126 insert_commit_data commit_data;
1127 std::pair<node_ptr, bool> ret =
1128 (node_algorithms::insert_unique_check
1129 (this->header_ptr(), key_of_value()(value), this->key_node_comp(this->key_comp()), commit_data));
1130 return std::pair<iterator, bool>
1131 ( ret.second ? this->insert_unique_commit(value, commit_data)
1132 : iterator(ret.first, this->priv_value_traits_ptr())
1133 , ret.second);
1134 }
1135
1136 //! <b>Requires</b>: value must be an lvalue, and "hint" must be
1137 //! a valid iterator
1138 //!
1139 //! <b>Effects</b>: Tries to insert x into the container, using "hint" as a hint
1140 //! to where it will be inserted.
1141 //!
1142 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1143 //! constant time (two comparisons in the worst case)
1144 //! if t is inserted immediately before hint.
1145 //!
1146 //! <b>Throws</b>: Nothing.
1147 //!
1148 //! <b>Note</b>: Does not affect the validity of iterators and references.
1149 //! No copy-constructors are called.
1150 iterator insert_unique(const_iterator hint, reference value)
1151 {
1152 insert_commit_data commit_data;
1153 std::pair<node_ptr, bool> ret =
1154 (node_algorithms::insert_unique_check
1155 (this->header_ptr(), hint.pointed_node(), key_of_value()(value), this->key_node_comp(this->key_comp()), commit_data));
1156 return ret.second ? this->insert_unique_commit(value, commit_data)
1157 : iterator(ret.first, this->priv_value_traits_ptr());
1158 }
1159
1160 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1161 //! of type value_type.
1162 //!
1163 //! <b>Effects</b>: Tries to insert each element of a range into the container.
1164 //!
1165 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1166 //! size of the range. However, it is linear in N if the range is already sorted
1167 //! by value_comp().
1168 //!
1169 //! <b>Throws</b>: Nothing.
1170 //!
1171 //! <b>Note</b>: Does not affect the validity of iterators and references.
1172 //! No copy-constructors are called.
1173 template<class Iterator>
1174 void insert_unique(Iterator b, Iterator e)
1175 {
1176 if(this->empty()){
1177 iterator iend(this->end());
1178 for (; b != e; ++b)
1179 this->insert_unique(iend, *b);
1180 }
1181 else{
1182 for (; b != e; ++b)
1183 this->insert_unique(*b);
1184 }
1185 }
1186
1187 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1188
1189 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
1190 //! a user provided key instead of the value itself.
1191 //!
1192 //! <b>Returns</b>: If there is an equivalent value
1193 //! returns a pair containing an iterator to the already present value
1194 //! and false. If the value can be inserted returns true in the returned
1195 //! pair boolean and fills "commit_data" that is meant to be used with
1196 //! the "insert_commit" function.
1197 //!
1198 //! <b>Complexity</b>: Average complexity is at most logarithmic.
1199 //!
1200 //! <b>Throws</b>: If the comp ordering function throws. Strong guarantee.
1201 std::pair<iterator, bool> insert_unique_check(const key_type &key, insert_commit_data &commit_data);
1202
1203 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
1204 //! a user provided key instead of the value itself, using "hint"
1205 //! as a hint to where it will be inserted.
1206 //!
1207 //! <b>Returns</b>: If there is an equivalent value
1208 //! returns a pair containing an iterator to the already present value
1209 //! and false. If the value can be inserted returns true in the returned
1210 //! pair boolean and fills "commit_data" that is meant to be used with
1211 //! the "insert_commit" function.
1212 //!
1213 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
1214 //! constant time if t is inserted immediately before hint.
1215 //!
1216 //! <b>Throws</b>: If the comp ordering function throws. Strong guarantee.
1217 std::pair<iterator, bool> insert_unique_check(const_iterator hint, const key_type &key, insert_commit_data &commit_data);
1218
1219 //! <b>Requires</b>: comp must be a comparison function that induces
1220 //! the same strict weak ordering as key_compare. The difference is that
1221 //! comp compares an arbitrary key with the contained values.
1222 //!
1223 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
1224 //! a user provided key instead of the value itself.
1225 //!
1226 //! <b>Returns</b>: If there is an equivalent value
1227 //! returns a pair containing an iterator to the already present value
1228 //! and false. If the value can be inserted returns true in the returned
1229 //! pair boolean and fills "commit_data" that is meant to be used with
1230 //! the "insert_commit" function.
1231 //!
1232 //! <b>Complexity</b>: Average complexity is at most logarithmic.
1233 //!
1234 //! <b>Throws</b>: If the comp ordering function throws. Strong guarantee.
1235 //!
1236 //! <b>Notes</b>: This function is used to improve performance when constructing
1237 //! a value_type is expensive: if there is an equivalent value
1238 //! the constructed object must be discarded. Many times, the part of the
1239 //! node that is used to impose the order is much cheaper to construct
1240 //! than the value_type and this function offers the possibility to use that
1241 //! part to check if the insertion will be successful.
1242 //!
1243 //! If the check is successful, the user can construct the value_type and use
1244 //! "insert_commit" to insert the object in constant-time. This gives a total
1245 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
1246 //!
1247 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
1248 //! objects are inserted or erased from the container.
1249 template<class KeyType, class KeyTypeKeyCompare>
1250 std::pair<iterator, bool> insert_unique_check
1251 (const KeyType &key, KeyTypeKeyCompare comp, insert_commit_data &commit_data);
1252
1253 //! <b>Requires</b>: comp must be a comparison function that induces
1254 //! the same strict weak ordering as key_compare. The difference is that
1255 //! comp compares an arbitrary key with the contained values.
1256 //!
1257 //! <b>Effects</b>: Checks if a value can be inserted in the container, using
1258 //! a user provided key instead of the value itself, using "hint"
1259 //! as a hint to where it will be inserted.
1260 //!
1261 //! <b>Returns</b>: If there is an equivalent value
1262 //! returns a pair containing an iterator to the already present value
1263 //! and false. If the value can be inserted returns true in the returned
1264 //! pair boolean and fills "commit_data" that is meant to be used with
1265 //! the "insert_commit" function.
1266 //!
1267 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
1268 //! constant time if t is inserted immediately before hint.
1269 //!
1270 //! <b>Throws</b>: If the comp ordering function throws. Strong guarantee.
1271 //!
1272 //! <b>Notes</b>: This function is used to improve performance when constructing
1273 //! a value_type is expensive: if there is an equivalent value
1274 //! the constructed object must be discarded. Many times, the part of the
1275 //! constructing that is used to impose the order is much cheaper to construct
1276 //! than the value_type and this function offers the possibility to use that key
1277 //! to check if the insertion will be successful.
1278 //!
1279 //! If the check is successful, the user can construct the value_type and use
1280 //! "insert_commit" to insert the object in constant-time. This can give a total
1281 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
1282 //!
1283 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
1284 //! objects are inserted or erased from the container.
1285 template<class KeyType, class KeyTypeKeyCompare>
1286 std::pair<iterator, bool> insert_unique_check
1287 (const_iterator hint, const KeyType &key
1288 ,KeyTypeKeyCompare comp, insert_commit_data &commit_data);
1289
1290 #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1291
1292 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
1293 //! must have been obtained from a previous call to "insert_check".
1294 //! No objects should have been inserted or erased from the container between
1295 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
1296 //!
1297 //! <b>Effects</b>: Inserts the value in the container using the information obtained
1298 //! from the "commit_data" that a previous "insert_check" filled.
1299 //!
1300 //! <b>Returns</b>: An iterator to the newly inserted object.
1301 //!
1302 //! <b>Complexity</b>: Constant time.
1303 //!
1304 //! <b>Throws</b>: Nothing.
1305 //!
1306 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
1307 //! previously executed to fill "commit_data". No value should be inserted or
1308 //! erased between the "insert_check" and "insert_commit" calls.
1309 iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
1310 {
1311 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
1312 if(safemode_or_autounlink)
1313 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
1314
1315 #if !(defined(BOOST_DISABLE_ASSERTS) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && defined(NDEBUG) ))
1316 //Test insertion position is correct
1317 iterator p(commit_data.node, this->priv_value_traits_ptr());
1318 if(!commit_data.link_left){
1319 ++p;
1320 }
1321 //Check if the insertion point is correct to detect wrong
1322 //uses insert_unique_check
1323 BOOST_ASSERT(( p == this->end() || !this->comp()(*p, value) ));
1324 BOOST_ASSERT(( p == this->begin() || !this->comp()(value, *--p) ));
1325 #endif
1326
1327 node_algorithms::insert_unique_commit
1328 (this->header_ptr(), to_insert, commit_data);
1329 this->sz_traits().increment();
1330 return iterator(to_insert, this->priv_value_traits_ptr());
1331 }
1332
1333 //! <b>Requires</b>: value must be an lvalue, "pos" must be
1334 //! a valid iterator (or end) and must be the succesor of value
1335 //! once inserted according to the predicate
1336 //!
1337 //! <b>Effects</b>: Inserts x into the container before "pos".
1338 //!
1339 //! <b>Complexity</b>: Constant time.
1340 //!
1341 //! <b>Throws</b>: Nothing.
1342 //!
1343 //! <b>Note</b>: This function does not check preconditions so if "pos" is not
1344 //! the successor of "value" container ordering invariant will be broken.
1345 //! This is a low-level function to be used only for performance reasons
1346 //! by advanced users.
1347 iterator insert_before(const_iterator pos, reference value)
1348 {
1349 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
1350 if(safemode_or_autounlink)
1351 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
1352 this->sz_traits().increment();
1353 return iterator(node_algorithms::insert_before
1354 (this->header_ptr(), pos.pointed_node(), to_insert), this->priv_value_traits_ptr());
1355 }
1356
1357 //! <b>Requires</b>: value must be an lvalue, and it must be no less
1358 //! than the greatest inserted key
1359 //!
1360 //! <b>Effects</b>: Inserts x into the container in the last position.
1361 //!
1362 //! <b>Complexity</b>: Constant time.
1363 //!
1364 //! <b>Throws</b>: Nothing.
1365 //!
1366 //! <b>Note</b>: This function does not check preconditions so if value is
1367 //! less than the greatest inserted key container ordering invariant will be broken.
1368 //! This function is slightly more efficient than using "insert_before".
1369 //! This is a low-level function to be used only for performance reasons
1370 //! by advanced users.
1371 void push_back(reference value)
1372 {
1373 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
1374 if(safemode_or_autounlink)
1375 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
1376 this->sz_traits().increment();
1377 node_algorithms::push_back(this->header_ptr(), to_insert);
1378 }
1379
1380 //! <b>Requires</b>: value must be an lvalue, and it must be no greater
1381 //! than the minimum inserted key
1382 //!
1383 //! <b>Effects</b>: Inserts x into the container in the first position.
1384 //!
1385 //! <b>Complexity</b>: Constant time.
1386 //!
1387 //! <b>Throws</b>: Nothing.
1388 //!
1389 //! <b>Note</b>: This function does not check preconditions so if value is
1390 //! greater than the minimum inserted key container ordering invariant will be broken.
1391 //! This function is slightly more efficient than using "insert_before".
1392 //! This is a low-level function to be used only for performance reasons
1393 //! by advanced users.
1394 void push_front(reference value)
1395 {
1396 node_ptr to_insert(this->get_value_traits().to_node_ptr(value));
1397 if(safemode_or_autounlink)
1398 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
1399 this->sz_traits().increment();
1400 node_algorithms::push_front(this->header_ptr(), to_insert);
1401 }
1402
1403 //! <b>Effects</b>: Erases the element pointed to by i.
1404 //!
1405 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1406 //!
1407 //! <b>Throws</b>: Nothing.
1408 //!
1409 //! <b>Note</b>: Invalidates the iterators (but not the references)
1410 //! to the erased elements. No destructors are called.
1411 iterator erase(const_iterator i)
1412 {
1413 const_iterator ret(i);
1414 ++ret;
1415 node_ptr to_erase(i.pointed_node());
1416 if(safemode_or_autounlink)
1417 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase));
1418 node_algorithms::erase(this->header_ptr(), to_erase);
1419 this->sz_traits().decrement();
1420 if(safemode_or_autounlink)
1421 node_algorithms::init(to_erase);
1422 return ret.unconst();
1423 }
1424
1425 //! <b>Effects</b>: Erases the range pointed to by b end e.
1426 //!
1427 //! <b>Complexity</b>: Average complexity for erase range is at most
1428 //! O(log(size() + N)), where N is the number of elements in the range.
1429 //!
1430 //! <b>Throws</b>: Nothing.
1431 //!
1432 //! <b>Note</b>: Invalidates the iterators (but not the references)
1433 //! to the erased elements. No destructors are called.
1434 iterator erase(const_iterator b, const_iterator e)
1435 { size_type n; return this->private_erase(b, e, n); }
1436
1437 //! <b>Effects</b>: Erases all the elements with the given value.
1438 //!
1439 //! <b>Returns</b>: The number of erased elements.
1440 //!
1441 //! <b>Complexity</b>: O(log(size() + N).
1442 //!
1443 //! <b>Throws</b>: Nothing.
1444 //!
1445 //! <b>Note</b>: Invalidates the iterators (but not the references)
1446 //! to the erased elements. No destructors are called.
1447 size_type erase(const key_type &key)
1448 { return this->erase(key, this->key_comp()); }
1449
1450 //! <b>Requires</b>: key is a value such that `*this` is partitioned with respect to
1451 //! comp(nk, key) and !comp(key, nk), with comp(nk, key) implying !comp(key, nk),
1452 //! with nk the key_type of a value_type inserted into `*this`.
1453 //!
1454 //! <b>Effects</b>: Erases all the elements with the given key.
1455 //! according to the comparison functor "comp".
1456 //!
1457 //! <b>Returns</b>: The number of erased elements.
1458 //!
1459 //! <b>Complexity</b>: O(log(size() + N).
1460 //!
1461 //! <b>Throws</b>: Nothing.
1462 //!
1463 //! <b>Note</b>: Invalidates the iterators (but not the references)
1464 //! to the erased elements. No destructors are called.
1465 template<class KeyType, class KeyTypeKeyCompare>
1466 BOOST_INTRUSIVE_DOC1ST(size_type
1467 , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
1468 erase(const KeyType& key, KeyTypeKeyCompare comp)
1469 {
1470 std::pair<iterator,iterator> p = this->equal_range(key, comp);
1471 size_type n;
1472 this->private_erase(p.first, p.second, n);
1473 return n;
1474 }
1475
1476 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1477 //!
1478 //! <b>Effects</b>: Erases the element pointed to by i.
1479 //! Disposer::operator()(pointer) is called for the removed element.
1480 //!
1481 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1482 //!
1483 //! <b>Throws</b>: Nothing.
1484 //!
1485 //! <b>Note</b>: Invalidates the iterators
1486 //! to the erased elements.
1487 template<class Disposer>
1488 iterator erase_and_dispose(const_iterator i, Disposer disposer)
1489 {
1490 node_ptr to_erase(i.pointed_node());
1491 iterator ret(this->erase(i));
1492 disposer(this->get_value_traits().to_value_ptr(to_erase));
1493 return ret;
1494 }
1495
1496 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1497 //!
1498 //! <b>Effects</b>: Erases all the elements with the given value.
1499 //! Disposer::operator()(pointer) is called for the removed elements.
1500 //!
1501 //! <b>Returns</b>: The number of erased elements.
1502 //!
1503 //! <b>Complexity</b>: O(log(size() + N).
1504 //!
1505 //! <b>Throws</b>: Nothing.
1506 //!
1507 //! <b>Note</b>: Invalidates the iterators (but not the references)
1508 //! to the erased elements. No destructors are called.
1509 template<class Disposer>
1510 size_type erase_and_dispose(const key_type &key, Disposer disposer)
1511 {
1512 std::pair<iterator,iterator> p = this->equal_range(key);
1513 size_type n;
1514 this->private_erase(p.first, p.second, n, disposer);
1515 return n;
1516 }
1517
1518 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1519 //!
1520 //! <b>Effects</b>: Erases the range pointed to by b end e.
1521 //! Disposer::operator()(pointer) is called for the removed elements.
1522 //!
1523 //! <b>Complexity</b>: Average complexity for erase range is at most
1524 //! O(log(size() + N)), where N is the number of elements in the range.
1525 //!
1526 //! <b>Throws</b>: Nothing.
1527 //!
1528 //! <b>Note</b>: Invalidates the iterators
1529 //! to the erased elements.
1530 template<class Disposer>
1531 iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
1532 { size_type n; return this->private_erase(b, e, n, disposer); }
1533
1534 //! <b>Requires</b>: key is a value such that `*this` is partitioned with respect to
1535 //! comp(nk, key) and !comp(key, nk), with comp(nk, key) implying !comp(key, nk)
1536 //! and nk the key_type of a value_type inserted into `*this`.
1537 //!
1538 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1539 //!
1540 //! <b>Effects</b>: Erases all the elements with the given key.
1541 //! according to the comparison functor "comp".
1542 //! Disposer::operator()(pointer) is called for the removed elements.
1543 //!
1544 //! <b>Returns</b>: The number of erased elements.
1545 //!
1546 //! <b>Complexity</b>: O(log(size() + N).
1547 //!
1548 //! <b>Throws</b>: Nothing.
1549 //!
1550 //! <b>Note</b>: Invalidates the iterators
1551 //! to the erased elements.
1552 template<class KeyType, class KeyTypeKeyCompare, class Disposer>
1553 BOOST_INTRUSIVE_DOC1ST(size_type
1554 , typename detail::disable_if_convertible<KeyTypeKeyCompare BOOST_INTRUSIVE_I const_iterator BOOST_INTRUSIVE_I size_type>::type)
1555 erase_and_dispose(const KeyType& key, KeyTypeKeyCompare comp, Disposer disposer)
1556 {
1557 std::pair<iterator,iterator> p = this->equal_range(key, comp);
1558 size_type n;
1559 this->private_erase(p.first, p.second, n, disposer);
1560 return n;
1561 }
1562
1563 //! <b>Effects</b>: Erases all of the elements.
1564 //!
1565 //! <b>Complexity</b>: Linear to the number of elements on the container.
1566 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1567 //!
1568 //! <b>Throws</b>: Nothing.
1569 //!
1570 //! <b>Note</b>: Invalidates the iterators (but not the references)
1571 //! to the erased elements. No destructors are called.
1572 void clear()
1573 {
1574 if(safemode_or_autounlink){
1575 this->clear_and_dispose(detail::null_disposer());
1576 }
1577 else{
1578 node_algorithms::init_header(this->header_ptr());
1579 this->sz_traits().set_size(0);
1580 }
1581 }
1582
1583 //! <b>Effects</b>: Erases all of the elements calling disposer(p) for
1584 //! each node to be erased.
1585 //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)),
1586 //! where N is the number of elements in the container.
1587 //!
1588 //! <b>Throws</b>: Nothing.
1589 //!
1590 //! <b>Note</b>: Invalidates the iterators (but not the references)
1591 //! to the erased elements. Calls N times to disposer functor.
1592 template<class Disposer>
1593 void clear_and_dispose(Disposer disposer)
1594 {
1595 node_algorithms::clear_and_dispose(this->header_ptr()
1596 , detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits()));
1597 node_algorithms::init_header(this->header_ptr());
1598 this->sz_traits().set_size(0);
1599 }
1600
1601 //! <b>Effects</b>: Returns the number of contained elements with the given value
1602 //!
1603 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1604 //! to number of objects with the given value.
1605 //!
1606 //! <b>Throws</b>: If `key_compare` throws.
1607 size_type count(const key_type &key) const
1608 { return size_type(this->count(key, this->key_comp())); }
1609
1610 //! <b>Requires</b>: key is a value such that `*this` is partitioned with respect to
1611 //! comp(nk, key) and !comp(key, nk), with comp(nk, key) implying !comp(key, nk),
1612 //! and nk the key_type of a value_type inserted into `*this`.
1613 //!
1614 //! <b>Effects</b>: Returns the number of contained elements with the given key
1615 //!
1616 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1617 //! to number of objects with the given key.
1618 //!
1619 //! <b>Throws</b>: If `comp` throws.
1620 template<class KeyType, class KeyTypeKeyCompare>
1621 size_type count(const KeyType &key, KeyTypeKeyCompare comp) const
1622 {
1623 std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
1624 size_type n = 0;
1625 for(; ret.first != ret.second; ++ret.first){ ++n; }
1626 return n;
1627 }
1628
1629 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1630
1631 //Add non-const overloads to theoretically const members
1632 //as some algorithms have different behavior when non-const versions are used (like splay trees).
1633 size_type count(const key_type &key)
1634 { return size_type(this->count(key, this->key_comp())); }
1635
1636 template<class KeyType, class KeyTypeKeyCompare>
1637 size_type count(const KeyType &key, KeyTypeKeyCompare comp)
1638 {
1639 std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
1640 size_type n = 0;
1641 for(; ret.first != ret.second; ++ret.first){ ++n; }
1642 return n;
1643 }
1644
1645 #else //defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1646
1647 //! <b>Effects</b>: Returns an iterator to the first element whose
1648 //! key is not less than k or end() if that element does not exist.
1649 //!
1650 //! <b>Complexity</b>: Logarithmic.
1651 //!
1652 //! <b>Throws</b>: If `key_compare` throws.
1653 iterator lower_bound(const key_type &key);
1654
1655 //! <b>Effects</b>: Returns an iterator to the first element whose
1656 //! key is not less than k or end() if that element does not exist.
1657 //!
1658 //! <b>Complexity</b>: Logarithmic.
1659 //!
1660 //! <b>Throws</b>: If `key_compare` throws.
1661 const_iterator lower_bound(const key_type &key) const;
1662
1663 //! @copydoc ::boost::intrusive::bstree::lower_bound(const key_type &)
1664 template<class KeyType, class KeyTypeKeyCompare>
1665 iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp);
1666
1667 //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyTypeKeyCompare)
1668 template<class KeyType, class KeyTypeKeyCompare>
1669 const_iterator lower_bound(const KeyType &key, KeyTypeKeyCompare comp) const;
1670
1671 //! <b>Effects</b>: Returns an iterator to the first element whose
1672 //! key is greater than k or end() if that element does not exist.
1673 //!
1674 //! <b>Complexity</b>: Logarithmic.
1675 //!
1676 //! <b>Throws</b>: If `key_compare` throws.
1677 iterator upper_bound(const key_type &key);
1678
1679 //! <b>Requires</b>: key is a value such that `*this` is partitioned with respect to
1680 //! !comp(key, nk), with nk the key_type of a value_type inserted into `*this`.
1681 //!
1682 //! <b>Effects</b>: Returns an iterator to the first element whose
1683 //! key is greater than k according to comp or end() if that element
1684 //! does not exist.
1685 //!
1686 //! <b>Complexity</b>: Logarithmic.
1687 //!
1688 //! <b>Throws</b>: If `comp` throws.
1689 template<class KeyType, class KeyTypeKeyCompare>
1690 iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp);
1691
1692 //! @copydoc ::boost::intrusive::bstree::upper_bound(const key_type &)
1693 const_iterator upper_bound(const key_type &key) const;
1694
1695 //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyTypeKeyCompare)
1696 template<class KeyType, class KeyTypeKeyCompare>
1697 const_iterator upper_bound(const KeyType &key, KeyTypeKeyCompare comp) const;
1698
1699 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1700 //! k or end() if that element does not exist.
1701 //!
1702 //! <b>Complexity</b>: Logarithmic.
1703 //!
1704 //! <b>Throws</b>: If `key_compare` throws.
1705 iterator find(const key_type &key);
1706
1707 //! <b>Requires</b>: key is a value such that `*this` is partitioned with respect to
1708 //! comp(nk, key) and !comp(key, nk), with comp(nk, key) implying !comp(key, nk),
1709 //! and nk the key_type of a value_type inserted into `*this`.
1710 //!
1711 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1712 //! k or end() if that element does not exist.
1713 //!
1714 //! <b>Complexity</b>: Logarithmic.
1715 //!
1716 //! <b>Throws</b>: If `comp` throws.
1717 template<class KeyType, class KeyTypeKeyCompare>
1718 iterator find(const KeyType &key, KeyTypeKeyCompare comp);
1719
1720 //! @copydoc ::boost::intrusive::bstree::find(const key_type &)
1721 const_iterator find(const key_type &key) const;
1722
1723 //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyTypeKeyCompare)
1724 template<class KeyType, class KeyTypeKeyCompare>
1725 const_iterator find(const KeyType &key, KeyTypeKeyCompare comp) const;
1726
1727 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1728 //! an empty range that indicates the position where those elements would be
1729 //! if they there is no elements with key k.
1730 //!
1731 //! <b>Complexity</b>: Logarithmic.
1732 //!
1733 //! <b>Throws</b>: If `key_compare` throws.
1734 std::pair<iterator,iterator> equal_range(const key_type &key);
1735
1736 //! <b>Requires</b>: key is a value such that `*this` is partitioned with respect to
1737 //! comp(nk, key) and !comp(key, nk), with comp(nk, key) implying !comp(key, nk),
1738 //! with nk the key_type of a value_type inserted into `*this`.
1739 //!
1740 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1741 //! an empty range that indicates the position where those elements would be
1742 //! if they there is no elements with key k.
1743 //!
1744 //! <b>Complexity</b>: Logarithmic.
1745 //!
1746 //! <b>Throws</b>: If `comp` throws.
1747 template<class KeyType, class KeyTypeKeyCompare>
1748 std::pair<iterator,iterator> equal_range(const KeyType &key, KeyTypeKeyCompare comp);
1749
1750 //! @copydoc ::boost::intrusive::bstree::equal_range(const key_type &)
1751 std::pair<const_iterator, const_iterator> equal_range(const key_type &key) const;
1752
1753 //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyTypeKeyCompare)
1754 template<class KeyType, class KeyTypeKeyCompare>
1755 std::pair<const_iterator, const_iterator>
1756 equal_range(const KeyType &key, KeyTypeKeyCompare comp) const;
1757
1758 //! <b>Requires</b>:
1759 //! `upper_key` shall not precede `lower_key` according to key_compare.
1760 //! [key_comp()(upper_key, lower_key) shall be false]
1761 //!
1762 //! If `lower_key` is equivalent to `upper_key`
1763 //! [!key_comp()(upper_key, lower_key) && !key_comp()(lower_key, upper_key)] then
1764 //! ('left_closed' || 'right_closed') must be false.
1765 //!
1766 //! <b>Effects</b>: Returns an a pair with the following criteria:
1767 //!
1768 //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise
1769 //!
1770 //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise
1771 //!
1772 //! <b>Complexity</b>: Logarithmic.
1773 //!
1774 //! <b>Throws</b>: If `key_compare` throws.
1775 //!
1776 //! <b>Note</b>: This function can be more efficient than calling upper_bound
1777 //! and lower_bound for lower_value and upper_value.
1778 //!
1779 //! <b>Note</b>: Experimental function, the interface might change in future releases.
1780 std::pair<iterator,iterator> bounded_range
1781 (const key_type &lower_key, const key_type &upper_value, bool left_closed, bool right_closed);
1782
1783 //! <b>Requires</b>:
1784 //! `lower_key` is a value such that `*this` is partitioned with respect to
1785 //! comp(nk, lower_key) if left_closed is true, with respect to !comp(lower_key, nk) otherwise.
1786 //!
1787 //! `upper_key` is a value such that `*this` is partitioned with respect to
1788 //! !comp(upper_key, nk) if right_closed is true, with respect to comp(nk, upper_key) otherwise.
1789 //!
1790 //! `upper_key` shall not precede `lower_key` according to comp
1791 //! [comp(upper_key, lower_key) shall be false]
1792 //!
1793 //! If `lower_key` is equivalent to `upper_key`
1794 //! [!comp(upper_key, lower_key) && !comp(lower_key, upper_key)] then
1795 //! ('left_closed' || 'right_closed') must be false.
1796 //!
1797 //! <b>Effects</b>: Returns an a pair with the following criteria:
1798 //!
1799 //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise
1800 //!
1801 //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise
1802 //!
1803 //! <b>Complexity</b>: Logarithmic.
1804 //!
1805 //! <b>Throws</b>: If `comp` throws.
1806 //!
1807 //! <b>Note</b>: This function can be more efficient than calling upper_bound
1808 //! and lower_bound for lower_key and upper_key.
1809 //!
1810 //! <b>Note</b>: Experimental function, the interface might change in future releases.
1811 template<class KeyType, class KeyTypeKeyCompare>
1812 std::pair<iterator,iterator> bounded_range
1813 (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed);
1814
1815 //! @copydoc ::boost::intrusive::bstree::bounded_range(const key_type &,const key_type &,bool,bool)
1816 std::pair<const_iterator,const_iterator> bounded_range
1817 (const key_type &lower_key, const key_type &upper_key, bool left_closed, bool right_closed) const;
1818
1819 //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyTypeKeyCompare,bool,bool)
1820 template<class KeyType, class KeyTypeKeyCompare>
1821 std::pair<const_iterator,const_iterator> bounded_range
1822 (const KeyType &lower_key, const KeyType &upper_key, KeyTypeKeyCompare comp, bool left_closed, bool right_closed) const;
1823
1824 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1825 //! appropriate type. Otherwise the behavior is undefined.
1826 //!
1827 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
1828 //! that points to the value
1829 //!
1830 //! <b>Complexity</b>: Constant.
1831 //!
1832 //! <b>Throws</b>: Nothing.
1833 //!
1834 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1835 //! is stateless.
1836 static iterator s_iterator_to(reference value);
1837
1838 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1839 //! appropriate type. Otherwise the behavior is undefined.
1840 //!
1841 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1842 //! set that points to the value
1843 //!
1844 //! <b>Complexity</b>: Constant.
1845 //!
1846 //! <b>Throws</b>: Nothing.
1847 //!
1848 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1849 //! is stateless.
1850 static const_iterator s_iterator_to(const_reference value);
1851
1852 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1853 //! appropriate type. Otherwise the behavior is undefined.
1854 //!
1855 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
1856 //! that points to the value
1857 //!
1858 //! <b>Complexity</b>: Constant.
1859 //!
1860 //! <b>Throws</b>: Nothing.
1861 iterator iterator_to(reference value);
1862
1863 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1864 //! appropriate type. Otherwise the behavior is undefined.
1865 //!
1866 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1867 //! set that points to the value
1868 //!
1869 //! <b>Complexity</b>: Constant.
1870 //!
1871 //! <b>Throws</b>: Nothing.
1872 const_iterator iterator_to(const_reference value) const;
1873
1874 //! <b>Requires</b>: value shall not be in a container.
1875 //!
1876 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
1877 //! state.
1878 //!
1879 //! <b>Throws</b>: Nothing.
1880 //!
1881 //! <b>Complexity</b>: Constant time.
1882 //!
1883 //! <b>Note</b>: This function puts the hook in the well-known default state
1884 //! used by auto_unlink and safe hooks.
1885 static void init_node(reference value);
1886
1887 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1888
1889 //! <b>Effects</b>: Unlinks the leftmost node from the container.
1890 //!
1891 //! <b>Complexity</b>: Average complexity is constant time.
1892 //!
1893 //! <b>Throws</b>: Nothing.
1894 //!
1895 //! <b>Notes</b>: This function breaks the container and the container can
1896 //! only be used for more unlink_leftmost_without_rebalance calls.
1897 //! This function is normally used to achieve a step by step
1898 //! controlled destruction of the container.
1899 pointer unlink_leftmost_without_rebalance()
1900 {
1901 node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance
1902 (this->header_ptr()));
1903 if(!to_be_disposed)
1904 return 0;
1905 this->sz_traits().decrement();
1906 if(safemode_or_autounlink)//If this is commented does not work with normal_link
1907 node_algorithms::init(to_be_disposed);
1908 return this->get_value_traits().to_value_ptr(to_be_disposed);
1909 }
1910
1911 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1912
1913 //! <b>Requires</b>: replace_this must be a valid iterator of *this
1914 //! and with_this must not be inserted in any container.
1915 //!
1916 //! <b>Effects</b>: Replaces replace_this in its position in the
1917 //! container with with_this. The container does not need to be rebalanced.
1918 //!
1919 //! <b>Complexity</b>: Constant.
1920 //!
1921 //! <b>Throws</b>: Nothing.
1922 //!
1923 //! <b>Note</b>: This function will break container ordering invariants if
1924 //! with_this is not equivalent to *replace_this according to the
1925 //! ordering rules. This function is faster than erasing and inserting
1926 //! the node, since no rebalancing or comparison is needed.
1927 void replace_node(iterator replace_this, reference with_this);
1928
1929 //! <b>Effects</b>: Rebalances the tree.
1930 //!
1931 //! <b>Throws</b>: Nothing.
1932 //!
1933 //! <b>Complexity</b>: Linear.
1934 void rebalance();
1935
1936 //! <b>Requires</b>: old_root is a node of a tree.
1937 //!
1938 //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
1939 //!
1940 //! <b>Returns</b>: The new root of the subtree.
1941 //!
1942 //! <b>Throws</b>: Nothing.
1943 //!
1944 //! <b>Complexity</b>: Linear to the elements in the subtree.
1945 iterator rebalance_subtree(iterator root);
1946
1947 #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1948
1949 //! <b>Effects</b>: removes "value" from the container.
1950 //!
1951 //! <b>Throws</b>: Nothing.
1952 //!
1953 //! <b>Complexity</b>: Logarithmic time.
1954 //!
1955 //! <b>Note</b>: This static function is only usable with non-constant
1956 //! time size containers that have stateless comparison functors.
1957 //!
1958 //! If the user calls
1959 //! this function with a constant time size container or stateful comparison
1960 //! functor a compilation error will be issued.
1961 static void remove_node(reference value)
1962 {
1963 BOOST_STATIC_ASSERT((!constant_time_size));
1964 node_ptr to_remove(value_traits::to_node_ptr(value));
1965 node_algorithms::unlink(to_remove);
1966 if(safemode_or_autounlink)
1967 node_algorithms::init(to_remove);
1968 }
1969
1970 //! <b>Requires</b>: "source" container's Options can only can differ in the comparison
1971 //! function from *this.
1972 //!
1973 //! <b>Effects</b>: Attempts to extract each element in source and insert it into a using
1974 //! the comparison object of *this. If there is an element in a with key equivalent to the
1975 //! key of an element from source, then that element is not extracted from source.
1976 //!
1977 //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
1978 //! to those same elements but as members of *this. Iterators referring to the transferred
1979 //! elements will continue to refer to their elements, but they now behave as iterators into *this,
1980 //! not into source.
1981 //!
1982 //! <b>Throws</b>: Nothing unless the comparison object throws.
1983 //!
1984 //! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
1985 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1986 template<class T, class ...Options2> void merge_unique(bstree<T, Options2...> &);
1987 #else
1988 template<class Compare2>
1989 void merge_unique(bstree_impl
1990 <ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &source)
1991 #endif
1992 {
1993 node_ptr it (node_algorithms::begin_node(source.header_ptr()))
1994 , itend(node_algorithms::end_node (source.header_ptr()));
1995
1996 while(it != itend){
1997 node_ptr const p(it);
1998 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(p));
1999 it = node_algorithms::next_node(it);
2000 if( node_algorithms::transfer_unique(this->header_ptr(), this->key_node_comp(this->key_comp()), source.header_ptr(), p) ){
2001 source.sz_traits().decrement();
2002 this->sz_traits().increment();
2003 }
2004 }
2005 }
2006
2007 //! <b>Requires</b>: "source" container's Options can only can differ in the comparison
2008 //! function from *this.
2009 //!
2010 //! <b>Effects</b>: Extracts each element in source and insert it into a using
2011 //! the comparison object of *this.
2012 //!
2013 //! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
2014 //! to those same elements but as members of *this. Iterators referring to the transferred
2015 //! elements will continue to refer to their elements, but they now behave as iterators into *this,
2016 //! not into source.
2017 //!
2018 //! <b>Throws</b>: Nothing unless the comparison object throws.
2019 //!
2020 //! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
2021 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2022 template<class T, class ...Options2> void merge_equal(bstree<T, Options2...> &);
2023 #else
2024 template<class Compare2>
2025 void merge_equal(bstree_impl
2026 <ValueTraits, VoidOrKeyOfValue, Compare2, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &source)
2027 #endif
2028 {
2029 node_ptr it (node_algorithms::begin_node(source.header_ptr()))
2030 , itend(node_algorithms::end_node (source.header_ptr()));
2031
2032 while(it != itend){
2033 node_ptr const p(it);
2034 BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!safemode_or_autounlink || !node_algorithms::unique(p));
2035 it = node_algorithms::next_node(it);
2036 node_algorithms::transfer_equal(this->header_ptr(), this->key_node_comp(this->key_comp()), source.header_ptr(), p);
2037 source.sz_traits().decrement();
2038 this->sz_traits().increment();
2039 }
2040 }
2041
2042 //! <b>Effects</b>: Asserts the integrity of the container with additional checks provided by the user.
2043 //!
2044 //! <b>Complexity</b>: Linear time.
2045 //!
2046 //! <b>Note</b>: The method might not have effect when asserts are turned off (e.g., with NDEBUG).
2047 //! Experimental function, interface might change in future versions.
2048 template <class ExtraChecker>
2049 void check(ExtraChecker extra_checker) const
2050 {
2051 typedef detail::key_nodeptr_comp<key_compare, value_traits, key_of_value> nodeptr_comp_t;
2052 nodeptr_comp_t nodeptr_comp(this->key_comp(), &this->get_value_traits());
2053 typedef typename get_node_checker<AlgoType, ValueTraits, nodeptr_comp_t, ExtraChecker>::type node_checker_t;
2054 typename node_checker_t::return_type checker_return;
2055 node_algorithms::check(this->header_ptr(), node_checker_t(nodeptr_comp, extra_checker), checker_return);
2056 if (constant_time_size)
2057 BOOST_INTRUSIVE_INVARIANT_ASSERT(this->sz_traits().get_size() == checker_return.node_count);
2058 }
2059
2060 //! <b>Effects</b>: Asserts the integrity of the container.
2061 //!
2062 //! <b>Complexity</b>: Linear time.
2063 //!
2064 //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG).
2065 //! Experimental function, interface might change in future versions.
2066 void check() const
2067 {
2068 check(detail::empty_node_checker<ValueTraits>());
2069 }
2070
2071 friend bool operator==(const bstree_impl &x, const bstree_impl &y)
2072 {
2073 if(constant_time_size && x.size() != y.size()){
2074 return false;
2075 }
2076 return boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend());
2077 }
2078
2079 friend bool operator!=(const bstree_impl &x, const bstree_impl &y)
2080 { return !(x == y); }
2081
2082 friend bool operator<(const bstree_impl &x, const bstree_impl &y)
2083 { return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
2084
2085 friend bool operator>(const bstree_impl &x, const bstree_impl &y)
2086 { return y < x; }
2087
2088 friend bool operator<=(const bstree_impl &x, const bstree_impl &y)
2089 { return !(x > y); }
2090
2091 friend bool operator>=(const bstree_impl &x, const bstree_impl &y)
2092 { return !(x < y); }
2093
2094 friend void swap(bstree_impl &x, bstree_impl &y)
2095 { x.swap(y); }
2096
2097 /// @cond
2098 private:
2099 template<class Disposer>
2100 iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
2101 {
2102 for(n = 0; b != e; ++n)
2103 this->erase_and_dispose(b++, disposer);
2104 return b.unconst();
2105 }
2106
2107 iterator private_erase(const_iterator b, const_iterator e, size_type &n)
2108 {
2109 for(n = 0; b != e; ++n)
2110 this->erase(b++);
2111 return b.unconst();
2112 }
2113 /// @endcond
2114 };
2115
2116 //! Helper metafunction to define a \c bstree that yields to the same type when the
2117 //! same options (either explicitly or implicitly) are used.
2118 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2119 template<class T, class ...Options>
2120 #else
2121 template<class T, class O1 = void, class O2 = void
2122 , class O3 = void, class O4 = void
2123 , class O5 = void, class O6 = void>
2124 #endif
2125 struct make_bstree
2126 {
2127 /// @cond
2128 typedef typename pack_options
2129 < bstree_defaults,
2130 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2131 O1, O2, O3, O4, O5, O6
2132 #else
2133 Options...
2134 #endif
2135 >::type packed_options;
2136
2137 typedef typename detail::get_value_traits
2138 <T, typename packed_options::proto_value_traits>::type value_traits;
2139
2140 typedef bstree_impl
2141 < value_traits
2142 , typename packed_options::key_of_value
2143 , typename packed_options::compare
2144 , typename packed_options::size_type
2145 , packed_options::constant_time_size
2146 , BsTreeAlgorithms
2147 , typename packed_options::header_holder_type
2148 > implementation_defined;
2149 /// @endcond
2150 typedef implementation_defined type;
2151 };
2152
2153
2154 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2155
2156 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2157 template<class T, class O1, class O2, class O3, class O4, class O5, class O6>
2158 #else
2159 template<class T, class ...Options>
2160 #endif
2161 class bstree
2162 : public make_bstree<T,
2163 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2164 O1, O2, O3, O4, O5, O6
2165 #else
2166 Options...
2167 #endif
2168 >::type
2169 {
2170 typedef typename make_bstree
2171 <T,
2172 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2173 O1, O2, O3, O4, O5, O6
2174 #else
2175 Options...
2176 #endif
2177 >::type Base;
2178 BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree)
2179
2180 public:
2181 typedef typename Base::key_compare key_compare;
2182 typedef typename Base::value_traits value_traits;
2183 typedef typename Base::iterator iterator;
2184 typedef typename Base::const_iterator const_iterator;
2185
2186 //Assert if passed value traits are compatible with the type
2187 BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value));
2188
2189 bstree()
2190 : Base()
2191 {}
2192
2193 explicit bstree( const key_compare &cmp, const value_traits &v_traits = value_traits())
2194 : Base(cmp, v_traits)
2195 {}
2196
2197 template<class Iterator>
2198 bstree( bool unique, Iterator b, Iterator e
2199 , const key_compare &cmp = key_compare()
2200 , const value_traits &v_traits = value_traits())
2201 : Base(unique, b, e, cmp, v_traits)
2202 {}
2203
2204 bstree(BOOST_RV_REF(bstree) x)
2205 : Base(BOOST_MOVE_BASE(Base, x))
2206 {}
2207
2208 bstree& operator=(BOOST_RV_REF(bstree) x)
2209 { return static_cast<bstree &>(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); }
2210
2211 template <class Cloner, class Disposer>
2212 void clone_from(const bstree &src, Cloner cloner, Disposer disposer)
2213 { Base::clone_from(src, cloner, disposer); }
2214
2215 template <class Cloner, class Disposer>
2216 void clone_from(BOOST_RV_REF(bstree) src, Cloner cloner, Disposer disposer)
2217 { Base::clone_from(BOOST_MOVE_BASE(Base, src), cloner, disposer); }
2218
2219 static bstree &container_from_end_iterator(iterator end_iterator)
2220 { return static_cast<bstree &>(Base::container_from_end_iterator(end_iterator)); }
2221
2222 static const bstree &container_from_end_iterator(const_iterator end_iterator)
2223 { return static_cast<const bstree &>(Base::container_from_end_iterator(end_iterator)); }
2224
2225 static bstree &container_from_iterator(iterator it)
2226 { return static_cast<bstree &>(Base::container_from_iterator(it)); }
2227
2228 static const bstree &container_from_iterator(const_iterator it)
2229 { return static_cast<const bstree &>(Base::container_from_iterator(it)); }
2230 };
2231
2232 #endif
2233 } //namespace intrusive
2234 } //namespace boost
2235
2236 #include <boost/intrusive/detail/config_end.hpp>
2237
2238 #endif //BOOST_INTRUSIVE_BSTREE_HPP