1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2008
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_SET_HPP
14 #define BOOST_INTRUSIVE_SET_HPP
16 #include <boost/intrusive/detail/config_begin.hpp>
17 #include <boost/intrusive/intrusive_fwd.hpp>
18 #include <boost/intrusive/detail/mpl.hpp>
19 #include <boost/intrusive/rbtree.hpp>
25 //! The class template set is an intrusive container, that mimics most of
26 //! the interface of std::set as described in the C++ standard.
28 //! The template parameter \c T is the type to be managed by the container.
29 //! The user can specify additional options and if no options are provided
30 //! default options are used.
32 //! The container supports the following options:
33 //! \c base_hook<>/member_hook<>/value_traits<>,
34 //! \c constant_time_size<>, \c size_type<> and
36 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
37 template<class T
, class ...Options
>
39 template<class Config
>
44 typedef rbtree_impl
<Config
> tree_type
;
47 set_impl (const set_impl
&);
51 set_impl
&operator =(const set_impl
&);
53 typedef tree_type implementation_defined
;
57 typedef typename
implementation_defined::value_type value_type
;
58 typedef typename
implementation_defined::value_traits value_traits
;
59 typedef typename
implementation_defined::pointer pointer
;
60 typedef typename
implementation_defined::const_pointer const_pointer
;
61 typedef typename
implementation_defined::reference reference
;
62 typedef typename
implementation_defined::const_reference const_reference
;
63 typedef typename
implementation_defined::difference_type difference_type
;
64 typedef typename
implementation_defined::size_type size_type
;
65 typedef typename
implementation_defined::value_compare value_compare
;
66 typedef typename
implementation_defined::key_compare key_compare
;
67 typedef typename
implementation_defined::iterator iterator
;
68 typedef typename
implementation_defined::const_iterator const_iterator
;
69 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
70 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
71 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
72 typedef typename
implementation_defined::node_traits node_traits
;
73 typedef typename
implementation_defined::node node
;
74 typedef typename
implementation_defined::node_ptr node_ptr
;
75 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
76 typedef typename
implementation_defined::node_algorithms node_algorithms
;
84 //! <b>Effects</b>: Constructs an empty set.
86 //! <b>Complexity</b>: Constant.
88 //! <b>Throws</b>: If value_traits::node_traits::node
89 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
90 //! or the copy constructor of the value_compare object throws.
91 set_impl( const value_compare
&cmp
= value_compare()
92 , const value_traits
&v_traits
= value_traits())
93 : tree_(cmp
, v_traits
)
96 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
97 //! cmp must be a comparison function that induces a strict weak ordering.
99 //! <b>Effects</b>: Constructs an empty set and inserts elements from
102 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
103 //! comp and otherwise N * log N, where N is std::distance(last, first).
105 //! <b>Throws</b>: If value_traits::node_traits::node
106 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
107 //! or the copy constructor/operator() of the value_compare object throws.
108 template<class Iterator
>
109 set_impl( Iterator b
, Iterator e
110 , const value_compare
&cmp
= value_compare()
111 , const value_traits
&v_traits
= value_traits())
112 : tree_(true, b
, e
, cmp
, v_traits
)
115 //! <b>Effects</b>: Detaches all elements from this. The objects in the set
116 //! are not deleted (i.e. no destructors are called).
118 //! <b>Complexity</b>: Linear to the number of elements on the container.
119 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
121 //! <b>Throws</b>: Nothing.
125 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the set.
127 //! <b>Complexity</b>: Constant.
129 //! <b>Throws</b>: Nothing.
131 { return tree_
.begin(); }
133 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set.
135 //! <b>Complexity</b>: Constant.
137 //! <b>Throws</b>: Nothing.
138 const_iterator
begin() const
139 { return tree_
.begin(); }
141 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set.
143 //! <b>Complexity</b>: Constant.
145 //! <b>Throws</b>: Nothing.
146 const_iterator
cbegin() const
147 { return tree_
.cbegin(); }
149 //! <b>Effects</b>: Returns an iterator pointing to the end of the set.
151 //! <b>Complexity</b>: Constant.
153 //! <b>Throws</b>: Nothing.
155 { return tree_
.end(); }
157 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set.
159 //! <b>Complexity</b>: Constant.
161 //! <b>Throws</b>: Nothing.
162 const_iterator
end() const
163 { return tree_
.end(); }
165 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set.
167 //! <b>Complexity</b>: Constant.
169 //! <b>Throws</b>: Nothing.
170 const_iterator
cend() const
171 { return tree_
.cend(); }
173 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
176 //! <b>Complexity</b>: Constant.
178 //! <b>Throws</b>: Nothing.
179 reverse_iterator
rbegin()
180 { return tree_
.rbegin(); }
182 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
183 //! of the reversed set.
185 //! <b>Complexity</b>: Constant.
187 //! <b>Throws</b>: Nothing.
188 const_reverse_iterator
rbegin() const
189 { return tree_
.rbegin(); }
191 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
192 //! of the reversed set.
194 //! <b>Complexity</b>: Constant.
196 //! <b>Throws</b>: Nothing.
197 const_reverse_iterator
crbegin() const
198 { return tree_
.crbegin(); }
200 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
201 //! of the reversed set.
203 //! <b>Complexity</b>: Constant.
205 //! <b>Throws</b>: Nothing.
206 reverse_iterator
rend()
207 { return tree_
.rend(); }
209 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
210 //! of the reversed set.
212 //! <b>Complexity</b>: Constant.
214 //! <b>Throws</b>: Nothing.
215 const_reverse_iterator
rend() const
216 { return tree_
.rend(); }
218 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
219 //! of the reversed set.
221 //! <b>Complexity</b>: Constant.
223 //! <b>Throws</b>: Nothing.
224 const_reverse_iterator
crend() const
225 { return tree_
.crend(); }
227 //! <b>Precondition</b>: end_iterator must be a valid end iterator
230 //! <b>Effects</b>: Returns a reference to the set associated to the end iterator
232 //! <b>Throws</b>: Nothing.
234 //! <b>Complexity</b>: Constant.
235 static set_impl
&container_from_end_iterator(iterator end_iterator
)
237 return *detail::parent_from_member
<set_impl
, tree_type
>
238 ( &tree_type::container_from_end_iterator(end_iterator
)
242 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
245 //! <b>Effects</b>: Returns a const reference to the set associated to the end iterator
247 //! <b>Throws</b>: Nothing.
249 //! <b>Complexity</b>: Constant.
250 static const set_impl
&container_from_end_iterator(const_iterator end_iterator
)
252 return *detail::parent_from_member
<set_impl
, tree_type
>
253 ( &tree_type::container_from_end_iterator(end_iterator
)
257 //! <b>Precondition</b>: it must be a valid iterator of set.
259 //! <b>Effects</b>: Returns a reference to the set associated to the iterator
261 //! <b>Throws</b>: Nothing.
263 //! <b>Complexity</b>: Logarithmic.
264 static set_impl
&container_from_iterator(iterator it
)
266 return *detail::parent_from_member
<set_impl
, tree_type
>
267 ( &tree_type::container_from_iterator(it
)
271 //! <b>Precondition</b>: it must be a valid const_iterator of set.
273 //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
275 //! <b>Throws</b>: Nothing.
277 //! <b>Complexity</b>: Logarithmic.
278 static const set_impl
&container_from_iterator(const_iterator it
)
280 return *detail::parent_from_member
<set_impl
, tree_type
>
281 ( &tree_type::container_from_iterator(it
)
285 //! <b>Effects</b>: Returns the key_compare object used by the set.
287 //! <b>Complexity</b>: Constant.
289 //! <b>Throws</b>: If key_compare copy-constructor throws.
290 key_compare
key_comp() const
291 { return tree_
.value_comp(); }
293 //! <b>Effects</b>: Returns the value_compare object used by the set.
295 //! <b>Complexity</b>: Constant.
297 //! <b>Throws</b>: If value_compare copy-constructor throws.
298 value_compare
value_comp() const
299 { return tree_
.value_comp(); }
301 //! <b>Effects</b>: Returns true if the container is empty.
303 //! <b>Complexity</b>: Constant.
305 //! <b>Throws</b>: Nothing.
307 { return tree_
.empty(); }
309 //! <b>Effects</b>: Returns the number of elements stored in the set.
311 //! <b>Complexity</b>: Linear to elements contained in *this if,
312 //! constant-time size option is enabled. Constant-time otherwise.
314 //! <b>Throws</b>: Nothing.
315 size_type
size() const
316 { return tree_
.size(); }
318 //! <b>Effects</b>: Swaps the contents of two sets.
320 //! <b>Complexity</b>: Constant.
322 //! <b>Throws</b>: If the swap() call for the comparison functor
323 //! found using ADL throws. Strong guarantee.
324 void swap(set_impl
& other
)
325 { tree_
.swap(other
.tree_
); }
327 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
328 //! Cloner should yield to nodes equivalent to the original nodes.
330 //! <b>Effects</b>: Erases all the elements from *this
331 //! calling Disposer::operator()(pointer), clones all the
332 //! elements from src calling Cloner::operator()(const_reference )
333 //! and inserts them on *this. Copies the predicate from the source container.
335 //! If cloner throws, all cloned elements are unlinked and disposed
336 //! calling Disposer::operator()(pointer).
338 //! <b>Complexity</b>: Linear to erased plus inserted elements.
340 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
341 template <class Cloner
, class Disposer
>
342 void clone_from(const set_impl
&src
, Cloner cloner
, Disposer disposer
)
343 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
345 //! <b>Requires</b>: value must be an lvalue
347 //! <b>Effects</b>: Tries to inserts value into the set.
349 //! <b>Returns</b>: If the value
350 //! is not already present inserts it and returns a pair containing the
351 //! iterator to the new value and true. If there is an equivalent value
352 //! returns a pair containing an iterator to the already present value
355 //! <b>Complexity</b>: Average complexity for insert element is at
356 //! most logarithmic.
358 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
360 //! <b>Note</b>: Does not affect the validity of iterators and references.
361 //! No copy-constructors are called.
362 std::pair
<iterator
, bool> insert(reference value
)
363 { return tree_
.insert_unique(value
); }
365 //! <b>Requires</b>: value must be an lvalue
367 //! <b>Effects</b>: Tries to to insert x into the set, using "hint"
368 //! as a hint to where it will be inserted.
370 //! <b>Returns</b>: An iterator that points to the position where the
371 //! new element was inserted into the set.
373 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
374 //! constant time if t is inserted immediately before hint.
376 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
378 //! <b>Note</b>: Does not affect the validity of iterators and references.
379 //! No copy-constructors are called.
380 iterator
insert(const_iterator hint
, reference value
)
381 { return tree_
.insert_unique(hint
, value
); }
383 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
384 //! the same strict weak ordering as value_compare. The difference is that
385 //! key_value_comp compares an arbitrary key with the contained values.
387 //! <b>Effects</b>: Checks if a value can be inserted in the set, using
388 //! a user provided key instead of the value itself.
390 //! <b>Returns</b>: If there is an equivalent value
391 //! returns a pair containing an iterator to the already present value
392 //! and false. If the value can be inserted returns true in the returned
393 //! pair boolean and fills "commit_data" that is meant to be used with
394 //! the "insert_commit" function.
396 //! <b>Complexity</b>: Average complexity is at most logarithmic.
398 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
400 //! <b>Notes</b>: This function is used to improve performance when constructing
401 //! a value_type is expensive: if there is an equivalent value
402 //! the constructed object must be discarded. Many times, the part of the
403 //! node that is used to impose the order is much cheaper to construct
404 //! than the value_type and this function offers the possibility to use that
405 //! part to check if the insertion will be successful.
407 //! If the check is successful, the user can construct the value_type and use
408 //! "insert_commit" to insert the object in constant-time. This gives a total
409 //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
411 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
412 //! objects are inserted or erased from the set.
413 template<class KeyType
, class KeyValueCompare
>
414 std::pair
<iterator
, bool> insert_check
415 (const KeyType
&key
, KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
416 { return tree_
.insert_unique_check(key
, key_value_comp
, commit_data
); }
418 //! <b>Requires</b>: key_value_comp must be a comparison function that induces
419 //! the same strict weak ordering as value_compare. The difference is that
420 //! key_value_comp compares an arbitrary key with the contained values.
422 //! <b>Effects</b>: Checks if a value can be inserted in the set, using
423 //! a user provided key instead of the value itself, using "hint"
424 //! as a hint to where it will be inserted.
426 //! <b>Returns</b>: If there is an equivalent value
427 //! returns a pair containing an iterator to the already present value
428 //! and false. If the value can be inserted returns true in the returned
429 //! pair boolean and fills "commit_data" that is meant to be used with
430 //! the "insert_commit" function.
432 //! <b>Complexity</b>: Logarithmic in general, but it's amortized
433 //! constant time if t is inserted immediately before hint.
435 //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
437 //! <b>Notes</b>: This function is used to improve performance when constructing
438 //! a value_type is expensive: if there is an equivalent value
439 //! the constructed object must be discarded. Many times, the part of the
440 //! constructing that is used to impose the order is much cheaper to construct
441 //! than the value_type and this function offers the possibility to use that key
442 //! to check if the insertion will be successful.
444 //! If the check is successful, the user can construct the value_type and use
445 //! "insert_commit" to insert the object in constant-time. This can give a total
446 //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
448 //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
449 //! objects are inserted or erased from the set.
450 template<class KeyType
, class KeyValueCompare
>
451 std::pair
<iterator
, bool> insert_check
452 (const_iterator hint
, const KeyType
&key
453 ,KeyValueCompare key_value_comp
, insert_commit_data
&commit_data
)
454 { return tree_
.insert_unique_check(hint
, key
, key_value_comp
, commit_data
); }
456 //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
457 //! must have been obtained from a previous call to "insert_check".
458 //! No objects should have been inserted or erased from the set between
459 //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
461 //! <b>Effects</b>: Inserts the value in the set using the information obtained
462 //! from the "commit_data" that a previous "insert_check" filled.
464 //! <b>Returns</b>: An iterator to the newly inserted object.
466 //! <b>Complexity</b>: Constant time.
468 //! <b>Throws</b>: Nothing.
470 //! <b>Notes</b>: This function has only sense if a "insert_check" has been
471 //! previously executed to fill "commit_data". No value should be inserted or
472 //! erased between the "insert_check" and "insert_commit" calls.
473 iterator
insert_commit(reference value
, const insert_commit_data
&commit_data
)
474 { return tree_
.insert_unique_commit(value
, commit_data
); }
476 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
477 //! of type value_type.
479 //! <b>Effects</b>: Inserts a range into the set.
481 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
482 //! size of the range. However, it is linear in N if the range is already sorted
485 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
487 //! <b>Note</b>: Does not affect the validity of iterators and references.
488 //! No copy-constructors are called.
489 template<class Iterator
>
490 void insert(Iterator b
, Iterator e
)
491 { tree_
.insert_unique(b
, e
); }
493 //! <b>Effects</b>: Erases the element pointed to by pos.
495 //! <b>Complexity</b>: Average complexity is constant time.
497 //! <b>Returns</b>: An iterator to the element after the erased element.
499 //! <b>Throws</b>: Nothing.
501 //! <b>Note</b>: Invalidates the iterators (but not the references)
502 //! to the erased elements. No destructors are called.
503 iterator
erase(const_iterator i
)
504 { return tree_
.erase(i
); }
506 //! <b>Effects</b>: Erases the range pointed to by b end e.
508 //! <b>Complexity</b>: Average complexity for erase range is at most
509 //! O(log(size() + N)), where N is the number of elements in the range.
511 //! <b>Returns</b>: An iterator to the element after the erased elements.
513 //! <b>Throws</b>: Nothing.
515 //! <b>Note</b>: Invalidates the iterators (but not the references)
516 //! to the erased elements. No destructors are called.
517 iterator
erase(const_iterator b
, const_iterator e
)
518 { return tree_
.erase(b
, e
); }
520 //! <b>Effects</b>: Erases all the elements with the given value.
522 //! <b>Returns</b>: The number of erased elements.
524 //! <b>Complexity</b>: O(log(size()) + this->count(value)).
526 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
528 //! <b>Note</b>: Invalidates the iterators (but not the references)
529 //! to the erased elements. No destructors are called.
530 size_type
erase(const_reference value
)
531 { return tree_
.erase(value
); }
533 //! <b>Effects</b>: Erases all the elements that compare equal with
534 //! the given key and the given comparison functor.
536 //! <b>Returns</b>: The number of erased elements.
538 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
540 //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
542 //! <b>Note</b>: Invalidates the iterators (but not the references)
543 //! to the erased elements. No destructors are called.
544 template<class KeyType
, class KeyValueCompare
>
545 size_type
erase(const KeyType
& key
, KeyValueCompare comp
547 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
550 { return tree_
.erase(key
, comp
); }
552 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
554 //! <b>Effects</b>: Erases the element pointed to by pos.
555 //! Disposer::operator()(pointer) is called for the removed element.
557 //! <b>Complexity</b>: Average complexity for erase element is constant time.
559 //! <b>Returns</b>: An iterator to the element after the erased element.
561 //! <b>Throws</b>: Nothing.
563 //! <b>Note</b>: Invalidates the iterators
564 //! to the erased elements.
565 template<class Disposer
>
566 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
567 { return tree_
.erase_and_dispose(i
, disposer
); }
569 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
570 template<class Disposer
>
571 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
572 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
575 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
577 //! <b>Effects</b>: Erases the range pointed to by b end e.
578 //! Disposer::operator()(pointer) is called for the removed elements.
580 //! <b>Complexity</b>: Average complexity for erase range is at most
581 //! O(log(size() + N)), where N is the number of elements in the range.
583 //! <b>Returns</b>: An iterator to the element after the erased elements.
585 //! <b>Throws</b>: Nothing.
587 //! <b>Note</b>: Invalidates the iterators
588 //! to the erased elements.
589 template<class Disposer
>
590 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
591 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
593 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
595 //! <b>Effects</b>: Erases all the elements with the given value.
596 //! Disposer::operator()(pointer) is called for the removed elements.
598 //! <b>Throws</b>: If the internal value_compare ordering function throws.
600 //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.
602 //! <b>Throws</b>: Nothing.
604 //! <b>Note</b>: Invalidates the iterators (but not the references)
605 //! to the erased elements. No destructors are called.
606 template<class Disposer
>
607 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
608 { return tree_
.erase_and_dispose(value
, disposer
); }
610 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
612 //! <b>Effects</b>: Erases all the elements with the given key.
613 //! according to the comparison functor "comp".
614 //! Disposer::operator()(pointer) is called for the removed elements.
616 //! <b>Returns</b>: The number of erased elements.
618 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
620 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
622 //! <b>Note</b>: Invalidates the iterators
623 //! to the erased elements.
624 template<class KeyType
, class KeyValueCompare
, class Disposer
>
625 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
627 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
630 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
632 //! <b>Effects</b>: Erases all the elements of the container.
634 //! <b>Complexity</b>: Linear to the number of elements on the container.
635 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
637 //! <b>Throws</b>: Nothing.
639 //! <b>Note</b>: Invalidates the iterators (but not the references)
640 //! to the erased elements. No destructors are called.
642 { return tree_
.clear(); }
644 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
646 //! <b>Effects</b>: Erases all the elements of the container.
648 //! <b>Complexity</b>: Linear to the number of elements on the container.
649 //! Disposer::operator()(pointer) is called for the removed elements.
651 //! <b>Throws</b>: Nothing.
653 //! <b>Note</b>: Invalidates the iterators (but not the references)
654 //! to the erased elements. No destructors are called.
655 template<class Disposer
>
656 void clear_and_dispose(Disposer disposer
)
657 { return tree_
.clear_and_dispose(disposer
); }
659 //! <b>Effects</b>: Returns the number of contained elements with the given key
661 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
662 //! to number of objects with the given key.
664 //! <b>Throws</b>: If the internal value_compare ordering function throws.
665 size_type
count(const_reference value
) const
666 { return tree_
.find(value
) != end(); }
668 //! <b>Effects</b>: Returns the number of contained elements with the same key
669 //! compared with the given comparison functor.
671 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
672 //! to number of objects with the given key.
674 //! <b>Throws</b>: If comp ordering function throws.
675 template<class KeyType
, class KeyValueCompare
>
676 size_type
count(const KeyType
& key
, KeyValueCompare comp
) const
677 { return tree_
.find(key
, comp
) != end(); }
679 //! <b>Effects</b>: Returns an iterator to the first element whose
680 //! key is not less than k or end() if that element does not exist.
682 //! <b>Complexity</b>: Logarithmic.
684 //! <b>Throws</b>: If the internal value_compare ordering function throws.
685 iterator
lower_bound(const_reference value
)
686 { return tree_
.lower_bound(value
); }
688 //! <b>Requires</b>: comp must imply the same element order as
689 //! value_compare. Usually key is the part of the value_type
690 //! that is used in the ordering functor.
692 //! <b>Effects</b>: Returns an iterator to the first element whose
693 //! key according to the comparison functor is not less than k or
694 //! end() if that element does not exist.
696 //! <b>Complexity</b>: Logarithmic.
698 //! <b>Throws</b>: If comp ordering function throws.
700 //! <b>Note</b>: This function is used when constructing a value_type
701 //! is expensive and the value_type can be compared with a cheaper
702 //! key type. Usually this key is part of the value_type.
703 template<class KeyType
, class KeyValueCompare
>
704 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
705 { return tree_
.lower_bound(key
, comp
); }
707 //! <b>Effects</b>: Returns a const iterator to the first element whose
708 //! key is not less than k or end() if that element does not exist.
710 //! <b>Complexity</b>: Logarithmic.
712 //! <b>Throws</b>: If the internal value_compare ordering function throws.
713 const_iterator
lower_bound(const_reference value
) const
714 { return tree_
.lower_bound(value
); }
716 //! <b>Requires</b>: comp must imply the same element order as
717 //! value_compare. Usually key is the part of the value_type
718 //! that is used in the ordering functor.
720 //! <b>Effects</b>: Returns a const_iterator to the first element whose
721 //! key according to the comparison functor is not less than k or
722 //! end() if that element does not exist.
724 //! <b>Complexity</b>: Logarithmic.
726 //! <b>Throws</b>: If comp ordering function throws.
728 //! <b>Note</b>: This function is used when constructing a value_type
729 //! is expensive and the value_type can be compared with a cheaper
730 //! key type. Usually this key is part of the value_type.
731 template<class KeyType
, class KeyValueCompare
>
732 const_iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
) const
733 { return tree_
.lower_bound(key
, comp
); }
735 //! <b>Effects</b>: Returns an iterator to the first element whose
736 //! key is greater than k or end() if that element does not exist.
738 //! <b>Complexity</b>: Logarithmic.
740 //! <b>Throws</b>: If the internal value_compare ordering function throws.
741 iterator
upper_bound(const_reference value
)
742 { return tree_
.upper_bound(value
); }
744 //! <b>Requires</b>: comp must imply the same element order as
745 //! value_compare. Usually key is the part of the value_type
746 //! that is used in the ordering functor.
748 //! <b>Effects</b>: Returns an iterator to the first element whose
749 //! key according to the comparison functor is greater than key or
750 //! end() if that element does not exist.
752 //! <b>Complexity</b>: Logarithmic.
754 //! <b>Throws</b>: If comp ordering function throws.
756 //! <b>Note</b>: This function is used when constructing a value_type
757 //! is expensive and the value_type can be compared with a cheaper
758 //! key type. Usually this key is part of the value_type.
759 template<class KeyType
, class KeyValueCompare
>
760 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
761 { return tree_
.upper_bound(key
, comp
); }
763 //! <b>Effects</b>: Returns an iterator to the first element whose
764 //! key is greater than k or end() if that element does not exist.
766 //! <b>Complexity</b>: Logarithmic.
768 //! <b>Throws</b>: If the internal value_compare ordering function throws.
769 const_iterator
upper_bound(const_reference value
) const
770 { return tree_
.upper_bound(value
); }
772 //! <b>Requires</b>: comp must imply the same element order as
773 //! value_compare. Usually key is the part of the value_type
774 //! that is used in the ordering functor.
776 //! <b>Effects</b>: Returns a const_iterator to the first element whose
777 //! key according to the comparison functor is greater than key or
778 //! end() if that element does not exist.
780 //! <b>Complexity</b>: Logarithmic.
782 //! <b>Throws</b>: If comp ordering function throws.
784 //! <b>Note</b>: This function is used when constructing a value_type
785 //! is expensive and the value_type can be compared with a cheaper
786 //! key type. Usually this key is part of the value_type.
787 template<class KeyType
, class KeyValueCompare
>
788 const_iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
) const
789 { return tree_
.upper_bound(key
, comp
); }
791 //! <b>Effects</b>: Finds an iterator to the first element whose value is
792 //! "value" or end() if that element does not exist.
794 //! <b>Complexity</b>: Logarithmic.
796 //! <b>Throws</b>: If the internal value_compare ordering function throws.
797 iterator
find(const_reference value
)
798 { return tree_
.find(value
); }
800 //! <b>Requires</b>: comp must imply the same element order as
801 //! value_compare. Usually key is the part of the value_type
802 //! that is used in the ordering functor.
804 //! <b>Effects</b>: Finds an iterator to the first element whose key is
805 //! "key" according to the comparison functor or end() if that element
808 //! <b>Complexity</b>: Logarithmic.
810 //! <b>Throws</b>: If comp ordering function throws.
812 //! <b>Note</b>: This function is used when constructing a value_type
813 //! is expensive and the value_type can be compared with a cheaper
814 //! key type. Usually this key is part of the value_type.
815 template<class KeyType
, class KeyValueCompare
>
816 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
817 { return tree_
.find(key
, comp
); }
819 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
820 //! "value" or end() if that element does not exist.
822 //! <b>Complexity</b>: Logarithmic.
824 //! <b>Throws</b>: If the internal value_compare ordering function throws.
825 const_iterator
find(const_reference value
) const
826 { return tree_
.find(value
); }
828 //! <b>Requires</b>: comp must imply the same element order as
829 //! value_compare. Usually key is the part of the value_type
830 //! that is used in the ordering functor.
832 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
833 //! "key" according to the comparison functor or end() if that element
836 //! <b>Complexity</b>: Logarithmic.
838 //! <b>Throws</b>: If comp ordering function throws.
840 //! <b>Note</b>: This function is used when constructing a value_type
841 //! is expensive and the value_type can be compared with a cheaper
842 //! key type. Usually this key is part of the value_type.
843 template<class KeyType
, class KeyValueCompare
>
844 const_iterator
find(const KeyType
& key
, KeyValueCompare comp
) const
845 { return tree_
.find(key
, comp
); }
847 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
848 //! an empty range that indicates the position where those elements would be
849 //! if they there is no elements with key k.
851 //! <b>Complexity</b>: Logarithmic.
853 //! <b>Throws</b>: If the internal value_compare ordering function throws.
854 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
855 { return tree_
.equal_range(value
); }
857 //! <b>Requires</b>: comp must imply the same element order as
858 //! value_compare. Usually key is the part of the value_type
859 //! that is used in the ordering functor.
861 //! <b>Effects</b>: Finds a range containing all elements whose key is k
862 //! according to the comparison functor or an empty range
863 //! that indicates the position where those elements would be
864 //! if they there is no elements with key k.
866 //! <b>Complexity</b>: Logarithmic.
868 //! <b>Throws</b>: If comp ordering function throws.
870 //! <b>Note</b>: This function is used when constructing a value_type
871 //! is expensive and the value_type can be compared with a cheaper
872 //! key type. Usually this key is part of the value_type.
873 template<class KeyType
, class KeyValueCompare
>
874 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
875 { return tree_
.equal_range(key
, comp
); }
877 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
878 //! an empty range that indicates the position where those elements would be
879 //! if they there is no elements with key k.
881 //! <b>Complexity</b>: Logarithmic.
883 //! <b>Throws</b>: If the internal value_compare ordering function throws.
884 std::pair
<const_iterator
, const_iterator
>
885 equal_range(const_reference value
) const
886 { return tree_
.equal_range(value
); }
888 //! <b>Requires</b>: comp must imply the same element order as
889 //! value_compare. Usually key is the part of the value_type
890 //! that is used in the ordering functor.
892 //! <b>Effects</b>: Finds a range containing all elements whose key is k
893 //! according to the comparison functor or an empty range
894 //! that indicates the position where those elements would be
895 //! if they there is no elements with key k.
897 //! <b>Complexity</b>: Logarithmic.
899 //! <b>Throws</b>: If comp ordering function throws.
901 //! <b>Note</b>: This function is used when constructing a value_type
902 //! is expensive and the value_type can be compared with a cheaper
903 //! key type. Usually this key is part of the value_type.
904 template<class KeyType
, class KeyValueCompare
>
905 std::pair
<const_iterator
, const_iterator
>
906 equal_range(const KeyType
& key
, KeyValueCompare comp
) const
907 { return tree_
.equal_range(key
, comp
); }
909 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
910 //! appropriate type. Otherwise the behavior is undefined.
912 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
913 //! that points to the value
915 //! <b>Complexity</b>: Constant.
917 //! <b>Throws</b>: Nothing.
919 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
921 static iterator
s_iterator_to(reference value
)
922 { return tree_type::s_iterator_to(value
); }
924 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
925 //! appropriate type. Otherwise the behavior is undefined.
927 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
928 //! set that points to the value
930 //! <b>Complexity</b>: Constant.
932 //! <b>Throws</b>: Nothing.
934 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
936 static const_iterator
s_iterator_to(const_reference value
)
937 { return tree_type::s_iterator_to(value
); }
939 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
940 //! appropriate type. Otherwise the behavior is undefined.
942 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
943 //! that points to the value
945 //! <b>Complexity</b>: Constant.
947 //! <b>Throws</b>: Nothing.
948 iterator
iterator_to(reference value
)
949 { return tree_
.iterator_to(value
); }
951 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
952 //! appropriate type. Otherwise the behavior is undefined.
954 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
955 //! set that points to the value
957 //! <b>Complexity</b>: Constant.
959 //! <b>Throws</b>: Nothing.
960 const_iterator
iterator_to(const_reference value
) const
961 { return tree_
.iterator_to(value
); }
963 //! <b>Requires</b>: value shall not be in a set/multiset.
965 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
968 //! <b>Throws</b>: Nothing.
970 //! <b>Complexity</b>: Constant time.
972 //! <b>Note</b>: This function puts the hook in the well-known default state
973 //! used by auto_unlink and safe hooks.
974 static void init_node(reference value
)
975 { tree_type::init_node(value
); }
977 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
979 //! <b>Complexity</b>: Average complexity is constant time.
981 //! <b>Throws</b>: Nothing.
983 //! <b>Notes</b>: This function breaks the tree and the tree can
984 //! only be used for more unlink_leftmost_without_rebalance calls.
985 //! This function is normally used to achieve a step by step
986 //! controlled destruction of the tree.
987 pointer
unlink_leftmost_without_rebalance()
988 { return tree_
.unlink_leftmost_without_rebalance(); }
990 //! <b>Requires</b>: replace_this must be a valid iterator of *this
991 //! and with_this must not be inserted in any tree.
993 //! <b>Effects</b>: Replaces replace_this in its position in the
994 //! tree with with_this. The tree does not need to be rebalanced.
996 //! <b>Complexity</b>: Constant.
998 //! <b>Throws</b>: Nothing.
1000 //! <b>Note</b>: This function will break container ordering invariants if
1001 //! with_this is not equivalent to *replace_this according to the
1002 //! ordering rules. This function is faster than erasing and inserting
1003 //! the node, since no rebalancing or comparison is needed.
1004 void replace_node(iterator replace_this
, reference with_this
)
1005 { tree_
.replace_node(replace_this
, with_this
); }
1008 friend bool operator==(const set_impl
&x
, const set_impl
&y
)
1009 { return x
.tree_
== y
.tree_
; }
1011 friend bool operator<(const set_impl
&x
, const set_impl
&y
)
1012 { return x
.tree_
< y
.tree_
; }
1016 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1017 template<class T
, class ...Options
>
1019 template<class Config
>
1021 inline bool operator!=
1022 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1023 (const set_impl
<T
, Options
...> &x
, const set_impl
<T
, Options
...> &y
)
1025 (const set_impl
<Config
> &x
, const set_impl
<Config
> &y
)
1027 { return !(x
== y
); }
1029 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1030 template<class T
, class ...Options
>
1032 template<class Config
>
1034 inline bool operator>
1035 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1036 (const set_impl
<T
, Options
...> &x
, const set_impl
<T
, Options
...> &y
)
1038 (const set_impl
<Config
> &x
, const set_impl
<Config
> &y
)
1042 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1043 template<class T
, class ...Options
>
1045 template<class Config
>
1047 inline bool operator<=
1048 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1049 (const set_impl
<T
, Options
...> &x
, const set_impl
<T
, Options
...> &y
)
1051 (const set_impl
<Config
> &x
, const set_impl
<Config
> &y
)
1053 { return !(y
< x
); }
1055 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1056 template<class T
, class ...Options
>
1058 template<class Config
>
1060 inline bool operator>=
1061 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1062 (const set_impl
<T
, Options
...> &x
, const set_impl
<T
, Options
...> &y
)
1064 (const set_impl
<Config
> &x
, const set_impl
<Config
> &y
)
1066 { return !(x
< y
); }
1068 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1069 template<class T
, class ...Options
>
1071 template<class Config
>
1074 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1075 (set_impl
<T
, Options
...> &x
, set_impl
<T
, Options
...> &y
)
1077 (set_impl
<Config
> &x
, set_impl
<Config
> &y
)
1081 //! Helper metafunction to define a \c set that yields to the same type when the
1082 //! same options (either explicitly or implicitly) are used.
1083 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1084 template<class T
, class ...Options
>
1086 template<class T
, class O1
= none
, class O2
= none
1087 , class O3
= none
, class O4
= none
>
1093 < typename make_rbtree_opt
<T
,
1094 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1100 > implementation_defined
;
1102 typedef implementation_defined type
;
1105 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
1106 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1107 template<class T
, class O1
, class O2
, class O3
, class O4
>
1109 template<class T
, class ...Options
>
1112 : public make_set
<T
,
1113 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1120 typedef typename make_set
1122 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
1130 typedef typename
Base::value_compare value_compare
;
1131 typedef typename
Base::value_traits value_traits
;
1132 typedef typename
Base::iterator iterator
;
1133 typedef typename
Base::const_iterator const_iterator
;
1135 //Assert if passed value traits are compatible with the type
1136 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
1138 set( const value_compare
&cmp
= value_compare()
1139 , const value_traits
&v_traits
= value_traits())
1140 : Base(cmp
, v_traits
)
1143 template<class Iterator
>
1144 set( Iterator b
, Iterator e
1145 , const value_compare
&cmp
= value_compare()
1146 , const value_traits
&v_traits
= value_traits())
1147 : Base(b
, e
, cmp
, v_traits
)
1150 static set
&container_from_end_iterator(iterator end_iterator
)
1151 { return static_cast<set
&>(Base::container_from_end_iterator(end_iterator
)); }
1153 static const set
&container_from_end_iterator(const_iterator end_iterator
)
1154 { return static_cast<const set
&>(Base::container_from_end_iterator(end_iterator
)); }
1156 static set
&container_from_iterator(iterator it
)
1157 { return static_cast<set
&>(Base::container_from_iterator(it
)); }
1159 static const set
&container_from_iterator(const_iterator it
)
1160 { return static_cast<const set
&>(Base::container_from_iterator(it
)); }
1165 //! The class template multiset is an intrusive container, that mimics most of
1166 //! the interface of std::multiset as described in the C++ standard.
1168 //! The template parameter \c T is the type to be managed by the container.
1169 //! The user can specify additional options and if no options are provided
1170 //! default options are used.
1172 //! The container supports the following options:
1173 //! \c base_hook<>/member_hook<>/value_traits<>,
1174 //! \c constant_time_size<>, \c size_type<> and
1176 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1177 template<class T
, class ...Options
>
1179 template<class Config
>
1184 typedef rbtree_impl
<Config
> tree_type
;
1186 //Non-copyable and non-assignable
1187 multiset_impl (const multiset_impl
&);
1188 multiset_impl
&operator =(const multiset_impl
&);
1189 typedef tree_type implementation_defined
;
1193 typedef typename
implementation_defined::value_type value_type
;
1194 typedef typename
implementation_defined::value_traits value_traits
;
1195 typedef typename
implementation_defined::pointer pointer
;
1196 typedef typename
implementation_defined::const_pointer const_pointer
;
1197 typedef typename
implementation_defined::reference reference
;
1198 typedef typename
implementation_defined::const_reference const_reference
;
1199 typedef typename
implementation_defined::difference_type difference_type
;
1200 typedef typename
implementation_defined::size_type size_type
;
1201 typedef typename
implementation_defined::value_compare value_compare
;
1202 typedef typename
implementation_defined::key_compare key_compare
;
1203 typedef typename
implementation_defined::iterator iterator
;
1204 typedef typename
implementation_defined::const_iterator const_iterator
;
1205 typedef typename
implementation_defined::reverse_iterator reverse_iterator
;
1206 typedef typename
implementation_defined::const_reverse_iterator const_reverse_iterator
;
1207 typedef typename
implementation_defined::insert_commit_data insert_commit_data
;
1208 typedef typename
implementation_defined::node_traits node_traits
;
1209 typedef typename
implementation_defined::node node
;
1210 typedef typename
implementation_defined::node_ptr node_ptr
;
1211 typedef typename
implementation_defined::const_node_ptr const_node_ptr
;
1212 typedef typename
implementation_defined::node_algorithms node_algorithms
;
1220 //! <b>Effects</b>: Constructs an empty multiset.
1222 //! <b>Complexity</b>: Constant.
1224 //! <b>Throws</b>: If value_traits::node_traits::node
1225 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1226 //! or the copy constructor/operator() of the value_compare object throws.
1227 multiset_impl( const value_compare
&cmp
= value_compare()
1228 , const value_traits
&v_traits
= value_traits())
1229 : tree_(cmp
, v_traits
)
1232 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
1233 //! cmp must be a comparison function that induces a strict weak ordering.
1235 //! <b>Effects</b>: Constructs an empty multiset and inserts elements from
1238 //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
1239 //! comp and otherwise N * log N, where N is the distance between first and last
1241 //! <b>Throws</b>: If value_traits::node_traits::node
1242 //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
1243 //! or the copy constructor/operator() of the value_compare object throws.
1244 template<class Iterator
>
1245 multiset_impl( Iterator b
, Iterator e
1246 , const value_compare
&cmp
= value_compare()
1247 , const value_traits
&v_traits
= value_traits())
1248 : tree_(false, b
, e
, cmp
, v_traits
)
1251 //! <b>Effects</b>: Detaches all elements from this. The objects in the set
1252 //! are not deleted (i.e. no destructors are called).
1254 //! <b>Complexity</b>: Linear to the number of elements on the container.
1255 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1257 //! <b>Throws</b>: Nothing.
1261 //! <b>Effects</b>: Returns an iterator pointing to the beginning of the multiset.
1263 //! <b>Complexity</b>: Constant.
1265 //! <b>Throws</b>: Nothing.
1267 { return tree_
.begin(); }
1269 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset.
1271 //! <b>Complexity</b>: Constant.
1273 //! <b>Throws</b>: Nothing.
1274 const_iterator
begin() const
1275 { return tree_
.begin(); }
1277 //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset.
1279 //! <b>Complexity</b>: Constant.
1281 //! <b>Throws</b>: Nothing.
1282 const_iterator
cbegin() const
1283 { return tree_
.cbegin(); }
1285 //! <b>Effects</b>: Returns an iterator pointing to the end of the multiset.
1287 //! <b>Complexity</b>: Constant.
1289 //! <b>Throws</b>: Nothing.
1291 { return tree_
.end(); }
1293 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset.
1295 //! <b>Complexity</b>: Constant.
1297 //! <b>Throws</b>: Nothing.
1298 const_iterator
end() const
1299 { return tree_
.end(); }
1301 //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset.
1303 //! <b>Complexity</b>: Constant.
1305 //! <b>Throws</b>: Nothing.
1306 const_iterator
cend() const
1307 { return tree_
.cend(); }
1309 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
1310 //! reversed multiset.
1312 //! <b>Complexity</b>: Constant.
1314 //! <b>Throws</b>: Nothing.
1315 reverse_iterator
rbegin()
1316 { return tree_
.rbegin(); }
1318 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1319 //! of the reversed multiset.
1321 //! <b>Complexity</b>: Constant.
1323 //! <b>Throws</b>: Nothing.
1324 const_reverse_iterator
rbegin() const
1325 { return tree_
.rbegin(); }
1327 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1328 //! of the reversed multiset.
1330 //! <b>Complexity</b>: Constant.
1332 //! <b>Throws</b>: Nothing.
1333 const_reverse_iterator
crbegin() const
1334 { return tree_
.crbegin(); }
1336 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1337 //! of the reversed multiset.
1339 //! <b>Complexity</b>: Constant.
1341 //! <b>Throws</b>: Nothing.
1342 reverse_iterator
rend()
1343 { return tree_
.rend(); }
1345 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1346 //! of the reversed multiset.
1348 //! <b>Complexity</b>: Constant.
1350 //! <b>Throws</b>: Nothing.
1351 const_reverse_iterator
rend() const
1352 { return tree_
.rend(); }
1354 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1355 //! of the reversed multiset.
1357 //! <b>Complexity</b>: Constant.
1359 //! <b>Throws</b>: Nothing.
1360 const_reverse_iterator
crend() const
1361 { return tree_
.crend(); }
1363 //! <b>Precondition</b>: end_iterator must be a valid end iterator
1366 //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator
1368 //! <b>Throws</b>: Nothing.
1370 //! <b>Complexity</b>: Constant.
1371 static multiset_impl
&container_from_end_iterator(iterator end_iterator
)
1373 return *detail::parent_from_member
<multiset_impl
, tree_type
>
1374 ( &tree_type::container_from_end_iterator(end_iterator
)
1375 , &multiset_impl::tree_
);
1378 //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
1381 //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator
1383 //! <b>Throws</b>: Nothing.
1385 //! <b>Complexity</b>: Constant.
1386 static const multiset_impl
&container_from_end_iterator(const_iterator end_iterator
)
1388 return *detail::parent_from_member
<multiset_impl
, tree_type
>
1389 ( &tree_type::container_from_end_iterator(end_iterator
)
1390 , &multiset_impl::tree_
);
1393 //! <b>Precondition</b>: it must be a valid iterator of multiset.
1395 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1397 //! <b>Throws</b>: Nothing.
1399 //! <b>Complexity</b>: Constant.
1400 static multiset_impl
&container_from_iterator(iterator it
)
1402 return *detail::parent_from_member
<multiset_impl
, tree_type
>
1403 ( &tree_type::container_from_iterator(it
)
1404 , &multiset_impl::tree_
);
1407 //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
1409 //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
1411 //! <b>Throws</b>: Nothing.
1413 //! <b>Complexity</b>: Constant.
1414 static const multiset_impl
&container_from_iterator(const_iterator it
)
1416 return *detail::parent_from_member
<multiset_impl
, tree_type
>
1417 ( &tree_type::container_from_iterator(it
)
1418 , &multiset_impl::tree_
);
1421 //! <b>Effects</b>: Returns the key_compare object used by the multiset.
1423 //! <b>Complexity</b>: Constant.
1425 //! <b>Throws</b>: If key_compare copy-constructor throws.
1426 key_compare
key_comp() const
1427 { return tree_
.value_comp(); }
1429 //! <b>Effects</b>: Returns the value_compare object used by the multiset.
1431 //! <b>Complexity</b>: Constant.
1433 //! <b>Throws</b>: If value_compare copy-constructor throws.
1434 value_compare
value_comp() const
1435 { return tree_
.value_comp(); }
1437 //! <b>Effects</b>: Returns true if the container is empty.
1439 //! <b>Complexity</b>: Constant.
1441 //! <b>Throws</b>: Nothing.
1443 { return tree_
.empty(); }
1445 //! <b>Effects</b>: Returns the number of elements stored in the multiset.
1447 //! <b>Complexity</b>: Linear to elements contained in *this if,
1448 //! constant-time size option is enabled. Constant-time otherwise.
1450 //! <b>Throws</b>: Nothing.
1451 size_type
size() const
1452 { return tree_
.size(); }
1454 //! <b>Effects</b>: Swaps the contents of two multisets.
1456 //! <b>Complexity</b>: Constant.
1458 //! <b>Throws</b>: If the swap() call for the comparison functor
1459 //! found using ADL throws. Strong guarantee.
1460 void swap(multiset_impl
& other
)
1461 { tree_
.swap(other
.tree_
); }
1463 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1464 //! Cloner should yield to nodes equivalent to the original nodes.
1466 //! <b>Effects</b>: Erases all the elements from *this
1467 //! calling Disposer::operator()(pointer), clones all the
1468 //! elements from src calling Cloner::operator()(const_reference )
1469 //! and inserts them on *this. Copies the predicate from the source container.
1471 //! If cloner throws, all cloned elements are unlinked and disposed
1472 //! calling Disposer::operator()(pointer).
1474 //! <b>Complexity</b>: Linear to erased plus inserted elements.
1476 //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
1477 template <class Cloner
, class Disposer
>
1478 void clone_from(const multiset_impl
&src
, Cloner cloner
, Disposer disposer
)
1479 { tree_
.clone_from(src
.tree_
, cloner
, disposer
); }
1481 //! <b>Requires</b>: value must be an lvalue
1483 //! <b>Effects</b>: Inserts value into the multiset.
1485 //! <b>Returns</b>: An iterator that points to the position where the new
1486 //! element was inserted.
1488 //! <b>Complexity</b>: Average complexity for insert element is at
1489 //! most logarithmic.
1491 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1493 //! <b>Note</b>: Does not affect the validity of iterators and references.
1494 //! No copy-constructors are called.
1495 iterator
insert(reference value
)
1496 { return tree_
.insert_equal(value
); }
1498 //! <b>Requires</b>: value must be an lvalue
1500 //! <b>Effects</b>: Inserts x into the multiset, using pos as a hint to
1501 //! where it will be inserted.
1503 //! <b>Returns</b>: An iterator that points to the position where the new
1504 //! element was inserted.
1506 //! <b>Complexity</b>: Logarithmic in general, but it is amortized
1507 //! constant time if t is inserted immediately before hint.
1509 //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
1511 //! <b>Note</b>: Does not affect the validity of iterators and references.
1512 //! No copy-constructors are called.
1513 iterator
insert(const_iterator hint
, reference value
)
1514 { return tree_
.insert_equal(hint
, value
); }
1516 //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
1517 //! of type value_type.
1519 //! <b>Effects</b>: Inserts a range into the multiset.
1521 //! <b>Returns</b>: An iterator that points to the position where the new
1522 //! element was inserted.
1524 //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
1525 //! size of the range. However, it is linear in N if the range is already sorted
1526 //! by value_comp().
1528 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1530 //! <b>Note</b>: Does not affect the validity of iterators and references.
1531 //! No copy-constructors are called.
1532 template<class Iterator
>
1533 void insert(Iterator b
, Iterator e
)
1534 { tree_
.insert_equal(b
, e
); }
1536 //! <b>Effects</b>: Erases the element pointed to by pos.
1538 //! <b>Complexity</b>: Average complexity is constant time.
1540 //! <b>Returns</b>: An iterator to the element after the erased element.
1542 //! <b>Throws</b>: Nothing.
1544 //! <b>Note</b>: Invalidates the iterators (but not the references)
1545 //! to the erased elements. No destructors are called.
1546 iterator
erase(const_iterator i
)
1547 { return tree_
.erase(i
); }
1549 //! <b>Effects</b>: Erases the range pointed to by b end e.
1551 //! <b>Returns</b>: An iterator to the element after the erased elements.
1553 //! <b>Complexity</b>: Average complexity for erase range is at most
1554 //! O(log(size() + N)), where N is the number of elements in the range.
1556 //! <b>Throws</b>: Nothing.
1558 //! <b>Note</b>: Invalidates the iterators (but not the references)
1559 //! to the erased elements. No destructors are called.
1560 iterator
erase(const_iterator b
, iterator e
)
1561 { return tree_
.erase(b
, e
); }
1563 //! <b>Effects</b>: Erases all the elements with the given value.
1565 //! <b>Returns</b>: The number of erased elements.
1567 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1569 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1571 //! <b>Note</b>: Invalidates the iterators (but not the references)
1572 //! to the erased elements. No destructors are called.
1573 size_type
erase(const_reference value
)
1574 { return tree_
.erase(value
); }
1576 //! <b>Effects</b>: Erases all the elements that compare equal with
1577 //! the given key and the given comparison functor.
1579 //! <b>Returns</b>: The number of erased elements.
1581 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1583 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1585 //! <b>Note</b>: Invalidates the iterators (but not the references)
1586 //! to the erased elements. No destructors are called.
1587 template<class KeyType
, class KeyValueCompare
>
1588 size_type
erase(const KeyType
& key
, KeyValueCompare comp
1590 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1593 { return tree_
.erase(key
, comp
); }
1595 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1597 //! <b>Returns</b>: An iterator to the element after the erased element.
1599 //! <b>Effects</b>: Erases the element pointed to by pos.
1600 //! Disposer::operator()(pointer) is called for the removed element.
1602 //! <b>Complexity</b>: Average complexity for erase element is constant time.
1604 //! <b>Throws</b>: Nothing.
1606 //! <b>Note</b>: Invalidates the iterators
1607 //! to the erased elements.
1608 template<class Disposer
>
1609 iterator
erase_and_dispose(const_iterator i
, Disposer disposer
)
1610 { return tree_
.erase_and_dispose(i
, disposer
); }
1612 #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
1613 template<class Disposer
>
1614 iterator
erase_and_dispose(iterator i
, Disposer disposer
)
1615 { return this->erase_and_dispose(const_iterator(i
), disposer
); }
1618 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1620 //! <b>Returns</b>: An iterator to the element after the erased elements.
1622 //! <b>Effects</b>: Erases the range pointed to by b end e.
1623 //! Disposer::operator()(pointer) is called for the removed elements.
1625 //! <b>Complexity</b>: Average complexity for erase range is at most
1626 //! O(log(size() + N)), where N is the number of elements in the range.
1628 //! <b>Throws</b>: Nothing.
1630 //! <b>Note</b>: Invalidates the iterators
1631 //! to the erased elements.
1632 template<class Disposer
>
1633 iterator
erase_and_dispose(const_iterator b
, const_iterator e
, Disposer disposer
)
1634 { return tree_
.erase_and_dispose(b
, e
, disposer
); }
1636 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1638 //! <b>Effects</b>: Erases all the elements with the given value.
1639 //! Disposer::operator()(pointer) is called for the removed elements.
1641 //! <b>Returns</b>: The number of erased elements.
1643 //! <b>Complexity</b>: O(log(size() + this->count(value)).
1645 //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
1647 //! <b>Note</b>: Invalidates the iterators (but not the references)
1648 //! to the erased elements. No destructors are called.
1649 template<class Disposer
>
1650 size_type
erase_and_dispose(const_reference value
, Disposer disposer
)
1651 { return tree_
.erase_and_dispose(value
, disposer
); }
1653 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1655 //! <b>Effects</b>: Erases all the elements with the given key.
1656 //! according to the comparison functor "comp".
1657 //! Disposer::operator()(pointer) is called for the removed elements.
1659 //! <b>Returns</b>: The number of erased elements.
1661 //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
1663 //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
1665 //! <b>Note</b>: Invalidates the iterators
1666 //! to the erased elements.
1667 template<class KeyType
, class KeyValueCompare
, class Disposer
>
1668 size_type
erase_and_dispose(const KeyType
& key
, KeyValueCompare comp
, Disposer disposer
1670 , typename
detail::enable_if_c
<!detail::is_convertible
<KeyValueCompare
, const_iterator
>::value
>::type
* = 0
1673 { return tree_
.erase_and_dispose(key
, comp
, disposer
); }
1675 //! <b>Effects</b>: Erases all the elements of the container.
1677 //! <b>Complexity</b>: Linear to the number of elements on the container.
1678 //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
1680 //! <b>Throws</b>: Nothing.
1682 //! <b>Note</b>: Invalidates the iterators (but not the references)
1683 //! to the erased elements. No destructors are called.
1685 { return tree_
.clear(); }
1687 //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
1689 //! <b>Effects</b>: Erases all the elements of the container.
1691 //! <b>Complexity</b>: Linear to the number of elements on the container.
1692 //! Disposer::operator()(pointer) is called for the removed elements.
1694 //! <b>Throws</b>: Nothing.
1696 //! <b>Note</b>: Invalidates the iterators (but not the references)
1697 //! to the erased elements. No destructors are called.
1698 template<class Disposer
>
1699 void clear_and_dispose(Disposer disposer
)
1700 { return tree_
.clear_and_dispose(disposer
); }
1702 //! <b>Effects</b>: Returns the number of contained elements with the given key
1704 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1705 //! to number of objects with the given key.
1707 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1708 size_type
count(const_reference value
) const
1709 { return tree_
.count(value
); }
1711 //! <b>Effects</b>: Returns the number of contained elements with the same key
1712 //! compared with the given comparison functor.
1714 //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
1715 //! to number of objects with the given key.
1717 //! <b>Throws</b>: If comp ordering function throws.
1718 template<class KeyType
, class KeyValueCompare
>
1719 size_type
count(const KeyType
& key
, KeyValueCompare comp
) const
1720 { return tree_
.count(key
, comp
); }
1722 //! <b>Effects</b>: Returns an iterator to the first element whose
1723 //! key is not less than k or end() if that element does not exist.
1725 //! <b>Complexity</b>: Logarithmic.
1727 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1728 iterator
lower_bound(const_reference value
)
1729 { return tree_
.lower_bound(value
); }
1731 //! <b>Requires</b>: comp must imply the same element order as
1732 //! value_compare. Usually key is the part of the value_type
1733 //! that is used in the ordering functor.
1735 //! <b>Effects</b>: Returns an iterator to the first element whose
1736 //! key according to the comparison functor is not less than k or
1737 //! end() if that element does not exist.
1739 //! <b>Complexity</b>: Logarithmic.
1741 //! <b>Throws</b>: If comp ordering function throws.
1743 //! <b>Note</b>: This function is used when constructing a value_type
1744 //! is expensive and the value_type can be compared with a cheaper
1745 //! key type. Usually this key is part of the value_type.
1746 template<class KeyType
, class KeyValueCompare
>
1747 iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
)
1748 { return tree_
.lower_bound(key
, comp
); }
1750 //! <b>Effects</b>: Returns a const iterator to the first element whose
1751 //! key is not less than k or end() if that element does not exist.
1753 //! <b>Complexity</b>: Logarithmic.
1755 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1756 const_iterator
lower_bound(const_reference value
) const
1757 { return tree_
.lower_bound(value
); }
1759 //! <b>Requires</b>: comp must imply the same element order as
1760 //! value_compare. Usually key is the part of the value_type
1761 //! that is used in the ordering functor.
1763 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1764 //! key according to the comparison functor is not less than k or
1765 //! end() if that element does not exist.
1767 //! <b>Complexity</b>: Logarithmic.
1769 //! <b>Throws</b>: If comp ordering function throws.
1771 //! <b>Note</b>: This function is used when constructing a value_type
1772 //! is expensive and the value_type can be compared with a cheaper
1773 //! key type. Usually this key is part of the value_type.
1774 template<class KeyType
, class KeyValueCompare
>
1775 const_iterator
lower_bound(const KeyType
& key
, KeyValueCompare comp
) const
1776 { return tree_
.lower_bound(key
, comp
); }
1778 //! <b>Effects</b>: Returns an iterator to the first element whose
1779 //! key is greater than k or end() if that element does not exist.
1781 //! <b>Complexity</b>: Logarithmic.
1783 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1784 iterator
upper_bound(const_reference value
)
1785 { return tree_
.upper_bound(value
); }
1787 //! <b>Requires</b>: comp must imply the same element order as
1788 //! value_compare. Usually key is the part of the value_type
1789 //! that is used in the ordering functor.
1791 //! <b>Effects</b>: Returns an iterator to the first element whose
1792 //! key according to the comparison functor is greater than key or
1793 //! end() if that element does not exist.
1795 //! <b>Complexity</b>: Logarithmic.
1797 //! <b>Throws</b>: If comp ordering function throws.
1799 //! <b>Note</b>: This function is used when constructing a value_type
1800 //! is expensive and the value_type can be compared with a cheaper
1801 //! key type. Usually this key is part of the value_type.
1802 template<class KeyType
, class KeyValueCompare
>
1803 iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
)
1804 { return tree_
.upper_bound(key
, comp
); }
1806 //! <b>Effects</b>: Returns an iterator to the first element whose
1807 //! key is greater than k or end() if that element does not exist.
1809 //! <b>Complexity</b>: Logarithmic.
1811 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1812 const_iterator
upper_bound(const_reference value
) const
1813 { return tree_
.upper_bound(value
); }
1815 //! <b>Requires</b>: comp must imply the same element order as
1816 //! value_compare. Usually key is the part of the value_type
1817 //! that is used in the ordering functor.
1819 //! <b>Effects</b>: Returns a const_iterator to the first element whose
1820 //! key according to the comparison functor is greater than key or
1821 //! end() if that element does not exist.
1823 //! <b>Complexity</b>: Logarithmic.
1825 //! <b>Throws</b>: If comp ordering function throws.
1827 //! <b>Note</b>: This function is used when constructing a value_type
1828 //! is expensive and the value_type can be compared with a cheaper
1829 //! key type. Usually this key is part of the value_type.
1830 template<class KeyType
, class KeyValueCompare
>
1831 const_iterator
upper_bound(const KeyType
& key
, KeyValueCompare comp
) const
1832 { return tree_
.upper_bound(key
, comp
); }
1834 //! <b>Effects</b>: Finds an iterator to the first element whose value is
1835 //! "value" or end() if that element does not exist.
1837 //! <b>Complexity</b>: Logarithmic.
1839 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1840 iterator
find(const_reference value
)
1841 { return tree_
.find(value
); }
1843 //! <b>Requires</b>: comp must imply the same element order as
1844 //! value_compare. Usually key is the part of the value_type
1845 //! that is used in the ordering functor.
1847 //! <b>Effects</b>: Finds an iterator to the first element whose key is
1848 //! "key" according to the comparison functor or end() if that element
1851 //! <b>Complexity</b>: Logarithmic.
1853 //! <b>Throws</b>: If comp ordering function throws.
1855 //! <b>Note</b>: This function is used when constructing a value_type
1856 //! is expensive and the value_type can be compared with a cheaper
1857 //! key type. Usually this key is part of the value_type.
1858 template<class KeyType
, class KeyValueCompare
>
1859 iterator
find(const KeyType
& key
, KeyValueCompare comp
)
1860 { return tree_
.find(key
, comp
); }
1862 //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
1863 //! "value" or end() if that element does not exist.
1865 //! <b>Complexity</b>: Logarithmic.
1867 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1868 const_iterator
find(const_reference value
) const
1869 { return tree_
.find(value
); }
1871 //! <b>Requires</b>: comp must imply the same element order as
1872 //! value_compare. Usually key is the part of the value_type
1873 //! that is used in the ordering functor.
1875 //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
1876 //! "key" according to the comparison functor or end() if that element
1879 //! <b>Complexity</b>: Logarithmic.
1881 //! <b>Throws</b>: If comp ordering function throws.
1883 //! <b>Note</b>: This function is used when constructing a value_type
1884 //! is expensive and the value_type can be compared with a cheaper
1885 //! key type. Usually this key is part of the value_type.
1886 template<class KeyType
, class KeyValueCompare
>
1887 const_iterator
find(const KeyType
& key
, KeyValueCompare comp
) const
1888 { return tree_
.find(key
, comp
); }
1890 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1891 //! an empty range that indicates the position where those elements would be
1892 //! if they there is no elements with key k.
1894 //! <b>Complexity</b>: Logarithmic.
1896 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1897 std::pair
<iterator
,iterator
> equal_range(const_reference value
)
1898 { return tree_
.equal_range(value
); }
1900 //! <b>Requires</b>: comp must imply the same element order as
1901 //! value_compare. Usually key is the part of the value_type
1902 //! that is used in the ordering functor.
1904 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1905 //! according to the comparison functor or an empty range
1906 //! that indicates the position where those elements would be
1907 //! if they there is no elements with key k.
1909 //! <b>Complexity</b>: Logarithmic.
1911 //! <b>Throws</b>: If comp ordering function throws.
1913 //! <b>Note</b>: This function is used when constructing a value_type
1914 //! is expensive and the value_type can be compared with a cheaper
1915 //! key type. Usually this key is part of the value_type.
1916 template<class KeyType
, class KeyValueCompare
>
1917 std::pair
<iterator
,iterator
> equal_range(const KeyType
& key
, KeyValueCompare comp
)
1918 { return tree_
.equal_range(key
, comp
); }
1920 //! <b>Effects</b>: Finds a range containing all elements whose key is k or
1921 //! an empty range that indicates the position where those elements would be
1922 //! if they there is no elements with key k.
1924 //! <b>Complexity</b>: Logarithmic.
1926 //! <b>Throws</b>: If the internal value_compare ordering function throws.
1927 std::pair
<const_iterator
, const_iterator
>
1928 equal_range(const_reference value
) const
1929 { return tree_
.equal_range(value
); }
1931 //! <b>Requires</b>: comp must imply the same element order as
1932 //! value_compare. Usually key is the part of the value_type
1933 //! that is used in the ordering functor.
1935 //! <b>Effects</b>: Finds a range containing all elements whose key is k
1936 //! according to the comparison functor or an empty range
1937 //! that indicates the position where those elements would be
1938 //! if they there is no elements with key k.
1940 //! <b>Complexity</b>: Logarithmic.
1942 //! <b>Throws</b>: If comp ordering function throws.
1944 //! <b>Note</b>: This function is used when constructing a value_type
1945 //! is expensive and the value_type can be compared with a cheaper
1946 //! key type. Usually this key is part of the value_type.
1947 template<class KeyType
, class KeyValueCompare
>
1948 std::pair
<const_iterator
, const_iterator
>
1949 equal_range(const KeyType
& key
, KeyValueCompare comp
) const
1950 { return tree_
.equal_range(key
, comp
); }
1952 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1953 //! appropriate type. Otherwise the behavior is undefined.
1955 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
1956 //! that points to the value
1958 //! <b>Complexity</b>: Constant.
1960 //! <b>Throws</b>: Nothing.
1962 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1964 static iterator
s_iterator_to(reference value
)
1965 { return tree_type::s_iterator_to(value
); }
1967 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1968 //! appropriate type. Otherwise the behavior is undefined.
1970 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1971 //! set that points to the value
1973 //! <b>Complexity</b>: Constant.
1975 //! <b>Throws</b>: Nothing.
1977 //! <b>Note</b>: This static function is available only if the <i>value traits</i>
1979 static const_iterator
s_iterator_to(const_reference value
)
1980 { return tree_type::s_iterator_to(value
); }
1982 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1983 //! appropriate type. Otherwise the behavior is undefined.
1985 //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
1986 //! that points to the value
1988 //! <b>Complexity</b>: Constant.
1990 //! <b>Throws</b>: Nothing.
1991 iterator
iterator_to(reference value
)
1992 { return tree_
.iterator_to(value
); }
1994 //! <b>Requires</b>: value must be an lvalue and shall be in a set of
1995 //! appropriate type. Otherwise the behavior is undefined.
1997 //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
1998 //! set that points to the value
2000 //! <b>Complexity</b>: Constant.
2002 //! <b>Throws</b>: Nothing.
2003 const_iterator
iterator_to(const_reference value
) const
2004 { return tree_
.iterator_to(value
); }
2006 //! <b>Requires</b>: value shall not be in a set/multiset.
2008 //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
2011 //! <b>Throws</b>: Nothing.
2013 //! <b>Complexity</b>: Constant time.
2015 //! <b>Note</b>: This function puts the hook in the well-known default state
2016 //! used by auto_unlink and safe hooks.
2017 static void init_node(reference value
)
2018 { tree_type::init_node(value
); }
2020 //! <b>Effects</b>: Unlinks the leftmost node from the tree.
2022 //! <b>Complexity</b>: Average complexity is constant time.
2024 //! <b>Throws</b>: Nothing.
2026 //! <b>Notes</b>: This function breaks the tree and the tree can
2027 //! only be used for more unlink_leftmost_without_rebalance calls.
2028 //! This function is normally used to achieve a step by step
2029 //! controlled destruction of the tree.
2030 pointer
unlink_leftmost_without_rebalance()
2031 { return tree_
.unlink_leftmost_without_rebalance(); }
2033 //! <b>Requires</b>: replace_this must be a valid iterator of *this
2034 //! and with_this must not be inserted in any tree.
2036 //! <b>Effects</b>: Replaces replace_this in its position in the
2037 //! tree with with_this. The tree does not need to be rebalanced.
2039 //! <b>Complexity</b>: Constant.
2041 //! <b>Throws</b>: Nothing.
2043 //! <b>Note</b>: This function will break container ordering invariants if
2044 //! with_this is not equivalent to *replace_this according to the
2045 //! ordering rules. This function is faster than erasing and inserting
2046 //! the node, since no rebalancing or comparison is needed.
2047 void replace_node(iterator replace_this
, reference with_this
)
2048 { tree_
.replace_node(replace_this
, with_this
); }
2050 //! <b>Effects</b>: removes "value" from the container.
2052 //! <b>Throws</b>: Nothing.
2054 //! <b>Complexity</b>: Logarithmic time.
2056 //! <b>Note</b>: This static function is only usable with non-constant
2057 //! time size containers that have stateless comparison functors.
2059 //! If the user calls
2060 //! this function with a constant time size container or stateful comparison
2061 //! functor a compilation error will be issued.
2062 static void remove_node(reference value
)
2063 { tree_type::remove_node(value
); }
2066 friend bool operator==(const multiset_impl
&x
, const multiset_impl
&y
)
2067 { return x
.tree_
== y
.tree_
; }
2069 friend bool operator<(const multiset_impl
&x
, const multiset_impl
&y
)
2070 { return x
.tree_
< y
.tree_
; }
2074 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2075 template<class T
, class ...Options
>
2077 template<class Config
>
2079 inline bool operator!=
2080 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2081 (const multiset_impl
<T
, Options
...> &x
, const multiset_impl
<T
, Options
...> &y
)
2083 (const multiset_impl
<Config
> &x
, const multiset_impl
<Config
> &y
)
2085 { return !(x
== y
); }
2087 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2088 template<class T
, class ...Options
>
2090 template<class Config
>
2092 inline bool operator>
2093 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2094 (const multiset_impl
<T
, Options
...> &x
, const multiset_impl
<T
, Options
...> &y
)
2096 (const multiset_impl
<Config
> &x
, const multiset_impl
<Config
> &y
)
2100 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2101 template<class T
, class ...Options
>
2103 template<class Config
>
2105 inline bool operator<=
2106 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2107 (const multiset_impl
<T
, Options
...> &x
, const multiset_impl
<T
, Options
...> &y
)
2109 (const multiset_impl
<Config
> &x
, const multiset_impl
<Config
> &y
)
2111 { return !(y
< x
); }
2113 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2114 template<class T
, class ...Options
>
2116 template<class Config
>
2118 inline bool operator>=
2119 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2120 (const multiset_impl
<T
, Options
...> &x
, const multiset_impl
<T
, Options
...> &y
)
2122 (const multiset_impl
<Config
> &x
, const multiset_impl
<Config
> &y
)
2124 { return !(x
< y
); }
2126 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2127 template<class T
, class ...Options
>
2129 template<class Config
>
2132 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
2133 (multiset_impl
<T
, Options
...> &x
, multiset_impl
<T
, Options
...> &y
)
2135 (multiset_impl
<Config
> &x
, multiset_impl
<Config
> &y
)
2139 //! Helper metafunction to define a \c multiset that yields to the same type when the
2140 //! same options (either explicitly or implicitly) are used.
2141 #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2142 template<class T
, class ...Options
>
2144 template<class T
, class O1
= none
, class O2
= none
2145 , class O3
= none
, class O4
= none
>
2147 struct make_multiset
2150 typedef multiset_impl
2151 < typename make_rbtree_opt
<T
,
2152 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2158 > implementation_defined
;
2160 typedef implementation_defined type
;
2163 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
2165 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2166 template<class T
, class O1
, class O2
, class O3
, class O4
>
2168 template<class T
, class ...Options
>
2171 : public make_multiset
<T
,
2172 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2179 typedef typename make_multiset
<T
,
2180 #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
2188 typedef typename
Base::value_compare value_compare
;
2189 typedef typename
Base::value_traits value_traits
;
2190 typedef typename
Base::iterator iterator
;
2191 typedef typename
Base::const_iterator const_iterator
;
2193 //Assert if passed value traits are compatible with the type
2194 BOOST_STATIC_ASSERT((detail::is_same
<typename
value_traits::value_type
, T
>::value
));
2196 multiset( const value_compare
&cmp
= value_compare()
2197 , const value_traits
&v_traits
= value_traits())
2198 : Base(cmp
, v_traits
)
2201 template<class Iterator
>
2202 multiset( Iterator b
, Iterator e
2203 , const value_compare
&cmp
= value_compare()
2204 , const value_traits
&v_traits
= value_traits())
2205 : Base(b
, e
, cmp
, v_traits
)
2208 static multiset
&container_from_end_iterator(iterator end_iterator
)
2209 { return static_cast<multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2211 static const multiset
&container_from_end_iterator(const_iterator end_iterator
)
2212 { return static_cast<const multiset
&>(Base::container_from_end_iterator(end_iterator
)); }
2214 static multiset
&container_from_iterator(iterator it
)
2215 { return static_cast<multiset
&>(Base::container_from_iterator(it
)); }
2217 static const multiset
&container_from_iterator(const_iterator it
)
2218 { return static_cast<const multiset
&>(Base::container_from_iterator(it
)); }
2223 } //namespace intrusive
2226 #include <boost/intrusive/detail/config_end.hpp>
2228 #endif //BOOST_INTRUSIVE_SET_HPP