--- /dev/null
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// (C) Copyright Olaf Krzikalla 2004-2006.\r
+// (C) Copyright Ion GaztaƱaga 2006-2007\r
+//\r
+// Distributed under the Boost Software License, Version 1.0.\r
+// (See accompanying file LICENSE_1_0.txt or copy at\r
+// http://www.boost.org/LICENSE_1_0.txt)\r
+//\r
+// See http://www.boost.org/libs/intrusive for documentation.\r
+//\r
+/////////////////////////////////////////////////////////////////////////////\r
+#ifndef BOOST_INTRUSIVE_ISET_HPP\r
+#define BOOST_INTRUSIVE_ISET_HPP\r
+\r
+#include "detail/config_begin.hpp"\r
+#include "detail/irbtree.hpp"\r
+#include <iterator>\r
+\r
+namespace boost {\r
+namespace intrusive {\r
+\r
+//! The class template iset is an intrusive container, that mimics most of \r
+//! the interface of std::set as described in the C++ standard.\r
+//! \r
+//! The template parameter ValueTraits is called "value traits". It stores\r
+//! information and operations about the type to be stored in the container.\r
+//!\r
+//! The template parameter Compare, provides a function object that can compare two \r
+//! element values as sort keys to determine their relative order in the set. \r
+//!\r
+//! If the user specifies ConstantTimeSize as "true", a member of type SizeType\r
+//! will be embedded in the class, that will keep track of the number of stored objects.\r
+//! This will allow constant-time O(1) size() member, instead of default O(N) size.\r
+template < class ValueTraits\r
+ , class Compare = std::less<typename ValueTraits::value_type>\r
+ , bool ConstantTimeSize = true\r
+ , class SizeType = std::size_t>\r
+class iset\r
+{\r
+ typedef detail::irbtree<ValueTraits, Compare, ConstantTimeSize, SizeType> tree_type;\r
+\r
+ //! This class is\r
+ //! non-copyable\r
+ iset (const iset&);\r
+\r
+ //! This class is\r
+ //! non-assignable\r
+ iset &operator =(const iset&);\r
+\r
+ typedef tree_type implementation_defined;\r
+\r
+ public:\r
+ typedef typename ValueTraits::value_type value_type;\r
+ typedef typename ValueTraits::pointer pointer;\r
+ typedef typename ValueTraits::const_pointer const_pointer;\r
+ typedef value_type& reference;\r
+ typedef const value_type& const_reference;\r
+ typedef SizeType size_type;\r
+ typedef typename std::iterator_traits\r
+ <pointer>::difference_type difference_type;\r
+ typedef value_type key_type;\r
+ typedef Compare value_compare;\r
+ typedef value_compare key_compare;\r
+ typedef typename implementation_defined::iterator iterator;\r
+ typedef typename implementation_defined::const_iterator const_iterator;\r
+ typedef typename implementation_defined::reverse_iterator reverse_iterator;\r
+ typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;\r
+ typedef typename implementation_defined::insert_commit_data insert_commit_data;\r
+\r
+ private:\r
+ tree_type tree_;\r
+\r
+ template <class V1, class P1, bool C1, class S1>\r
+ friend bool operator==(const iset<V1, P1, C1, S1>& x, const iset<V1, P1, C1, S1>& y);\r
+\r
+ template <class V1, class P1, bool C1, class S1>\r
+ friend bool operator<(const iset<V1, P1, C1, S1>& x, const iset<V1, P1, C1, S1>& y);\r
+\r
+ public:\r
+\r
+ //! <b>Effects</b>: Constructs an empty set. \r
+ //! \r
+ //! <b>Complexity</b>: Constant. \r
+ //! \r
+ //! <b>Throws</b>: If value_traits::node_traits::node\r
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)\r
+ //! or the copy constructor of the Compare object throws. \r
+ iset(const Compare &cmp = Compare()) \r
+ : tree_(cmp)\r
+ {}\r
+\r
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. \r
+ //! cmp must be a comparison function that induces a strict weak ordering.\r
+ //! \r
+ //! <b>Effects</b>: Constructs an empty set and inserts elements from \r
+ //! [b, e).\r
+ //! \r
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using \r
+ //! comp and otherwise N * log N, where N is std::distance(last, first).\r
+ //! \r
+ //! <b>Throws</b>: If value_traits::node_traits::node\r
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)\r
+ //! or the copy constructor/operator() of the Compare object throws. \r
+ template<class Iterator>\r
+ iset(Iterator b, Iterator e, const Compare &cmp = Compare())\r
+ : tree_(true, b, e, cmp)\r
+ { insert(b, e); }\r
+\r
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the set \r
+ //! are not deleted (i.e. no destructors are called).\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size()) + size()) if it's a safe-mode or auto-unlink\r
+ //! value. Otherwise constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ ~iset() \r
+ {}\r
+\r
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ iterator begin()\r
+ { return tree_.begin(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_iterator begin() const\r
+ { return tree_.begin(); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ iterator end()\r
+ { return tree_.end(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_iterator end() const\r
+ { return tree_.end(); }\r
+\r
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the\r
+ //! reversed set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ reverse_iterator rbegin()\r
+ { return tree_.rbegin(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning\r
+ //! of the reversed set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_reverse_iterator rbegin() const\r
+ { return tree_.rbegin(); }\r
+\r
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end\r
+ //! of the reversed set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ reverse_iterator rend()\r
+ { return tree_.rend(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end\r
+ //! of the reversed set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_reverse_iterator rend() const\r
+ { return tree_.rend(); }\r
+\r
+ //! <b>Effects</b>: Returns the key_compare object used by the set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: If key_compare copy-constructor throws.\r
+ key_compare key_comp() const\r
+ { return tree_.value_comp(); }\r
+\r
+ //! <b>Effects</b>: Returns the value_compare object used by the set.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: If value_compare copy-constructor throws.\r
+ value_compare value_comp() const\r
+ { return tree_.value_comp(); }\r
+\r
+ //! <b>Effects</b>: Returns true is the container is empty.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ bool empty() const\r
+ { return tree_.empty(); }\r
+\r
+ //! <b>Effects</b>: Returns the number of elements stored in the set.\r
+ //! \r
+ //! <b>Complexity</b>: Linear to elements contained in *this if,\r
+ //! ConstantTimeSize is false. Constant-time otherwise.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ size_type size() const\r
+ { return tree_.size(); }\r
+\r
+ //! <b>Effects</b>: Swaps the contents of two sets.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: If the swap() call for the comparison functor\r
+ //! found using ADL throws. Strong guarantee.\r
+ void swap(iset& other)\r
+ { tree_.swap(other.tree_); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases all the elements from *this\r
+ //! calling Destroyer::operator()(pointer), clones all the \r
+ //! elements from src calling Cloner::operator()(const value_type &)\r
+ //! and inserts them on *this.\r
+ //!\r
+ //! If cloner throws, all cloned elements are unlinked and destroyed\r
+ //! calling Destroyer::operator()(pointer).\r
+ //! \r
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.\r
+ //! \r
+ //! <b>Throws</b>: If cloner throws.\r
+ template <class Cloner, class Destroyer>\r
+ void clone_from(const iset &src, Cloner cloner, Destroyer destroyer)\r
+ { tree_.clone_from(src.tree_, cloner, destroyer); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue\r
+ //! \r
+ //! <b>Effects</b>: Tries to inserts value into the set.\r
+ //!\r
+ //! <b>Returns</b>: If the value\r
+ //! is not already present inserts it and returns a pair containing the\r
+ //! iterator to the new value and true. If the value is already present\r
+ //! returns a pair containing an iterator to the already present value\r
+ //! and false.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for insert element is at\r
+ //! most logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Strong guarantee.\r
+ //! \r
+ //! <b>Note</b>: Does not affect the validity of iterators and references.\r
+ //! No copy-constructors are called.\r
+ std::pair<iterator, bool> insert(value_type &value)\r
+ { return tree_.insert_unique(value); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue\r
+ //! \r
+ //! <b>Effects</b>: Tries to to insert x into the set, using "hint" \r
+ //! as a hint to where it will be inserted.\r
+ //!\r
+ //! <b>Returns</b>: An iterator that points to the position where the \r
+ //! new element was inserted into the set.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized\r
+ //! constant time if t is inserted immediately before hint.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Strong guarantee.\r
+ //! \r
+ //! <b>Note</b>: Does not affect the validity of iterators and references.\r
+ //! No copy-constructors are called.\r
+ iterator insert(const_iterator hint, value_type &value)\r
+ { return tree_.insert_unique(hint, value); }\r
+\r
+ //! <b>Requires</b>: key_value_comp must be a comparison function that induces \r
+ //! the same strict weak ordering as value_compare. The difference is that\r
+ //! key_value_comp compares an arbitrary key with the contained values.\r
+ //! \r
+ //! <b>Effects</b>: Checks if a value can be inserted in the set, using\r
+ //! a user provided key instead of the value itself.\r
+ //!\r
+ //! <b>Returns</b>: If an equivalent value is already present\r
+ //! returns a pair containing an iterator to the already present value\r
+ //! and false. If the value can be inserted returns true in the returned\r
+ //! pair boolean and fills "commit_data" that is meant to be used with\r
+ //! the "insert_commit" function.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.\r
+ //!\r
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.\r
+ //! \r
+ //! <b>Notes</b>: This function is used to improve performance when constructing\r
+ //! a value_type is expensive: if an equivalent value is already present\r
+ //! the constructed object must be discarded. Many times, the part of the\r
+ //! node that is used to impose the order is much cheaper to construct\r
+ //! than the value_type and this function offers the possibility to use that \r
+ //! part to check if the insertion will be successful.\r
+ //!\r
+ //! If the check is successful, the user can construct the value_type and use\r
+ //! "insert_commit" to insert the object in constant-time. This gives a total\r
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).\r
+ //!\r
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more\r
+ //! objects are inserted or erased from the set.\r
+ template<class KeyType, class KeyValueCompare>\r
+ std::pair<iterator, bool> insert_check\r
+ (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)\r
+ { return tree_.insert_unique_check(key, key_value_comp, commit_data); }\r
+\r
+ //! <b>Requires</b>: key_value_comp must be a comparison function that induces \r
+ //! the same strict weak ordering as value_compare. The difference is that\r
+ //! key_value_comp compares an arbitrary key with the contained values.\r
+ //! \r
+ //! <b>Effects</b>: Checks if a value can be inserted in the set, using\r
+ //! a user provided key instead of the value itself, using "hint" \r
+ //! as a hint to where it will be inserted.\r
+ //!\r
+ //! <b>Returns</b>: If an equivalent value is already present\r
+ //! returns a pair containing an iterator to the already present value\r
+ //! and false. If the value can be inserted returns true in the returned\r
+ //! pair boolean and fills "commit_data" that is meant to be used with\r
+ //! the "insert_commit" function.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized\r
+ //! constant time if t is inserted immediately before hint.\r
+ //!\r
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.\r
+ //! \r
+ //! <b>Notes</b>: This function is used to improve performance when constructing\r
+ //! a value_type is expensive: if the equivalent is already present\r
+ //! the constructed object must be discarded. Many times, the part of the\r
+ //! constructing that is used to impose the order is much cheaper to construct\r
+ //! than the value_type and this function offers the possibility to use that key \r
+ //! to check if the insertion will be successful.\r
+ //!\r
+ //! If the check is successful, the user can construct the value_type and use\r
+ //! "insert_commit" to insert the object in constant-time. This can give a total\r
+ //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).\r
+ //! \r
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more\r
+ //! objects are inserted or erased from the set.\r
+ template<class KeyType, class KeyValueCompare>\r
+ std::pair<iterator, bool> insert_check\r
+ (const_iterator hint, const KeyType &key\r
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)\r
+ { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data\r
+ //! must have been obtained from a previous call to "insert_check".\r
+ //! No objects should have been inserted or erased from the set between\r
+ //! the "insert_check" that filled "commit_data" and the call to "insert_commit".\r
+ //! \r
+ //! <b>Effects</b>: Inserts the value in the set using the information obtained\r
+ //! from the "commit_data" that a previous "insert_check" filled.\r
+ //!\r
+ //! <b>Returns</b>: An iterator to the newly inserted object.\r
+ //! \r
+ //! <b>Complexity</b>: Constant time.\r
+ //!\r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Notes</b>: This function has only sense if a "insert_check" has been\r
+ //! previously executed to fill "commit_data". No value should be inserted or\r
+ //! erased between the "insert_check" and "insert_commit" calls.\r
+ iterator insert_commit(value_type &value, const insert_commit_data &commit_data)\r
+ { return tree_.insert_unique_commit(value, commit_data); }\r
+\r
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue \r
+ //! of type value_type.\r
+ //! \r
+ //! <b>Effects</b>: Inserts a range into the set.\r
+ //! \r
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the \r
+ //! size of the range. However, it is linear in N if the range is already sorted \r
+ //! by value_comp().\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Does not affect the validity of iterators and references.\r
+ //! No copy-constructors are called.\r
+ template<class Iterator>\r
+ void insert(Iterator b, Iterator e)\r
+ { tree_.insert_unique(b, e); }\r
+\r
+ //! <b>Effects</b>: Erases the element pointed to by pos. \r
+ //! \r
+ //! <b>Complexity</b>: Average complexity is constant time.\r
+ //! \r
+ //! <b>Returns</b>: An iterator to the element after the erased element.\r
+ //!\r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ iterator erase(iterator i)\r
+ { return tree_.erase(i); }\r
+\r
+ //! <b>Effects</b>: Erases the range pointed to by b end e. \r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for erase range is at most \r
+ //! O(log(size() + N)), where N is the number of elements in the range.\r
+ //! \r
+ //! <b>Returns</b>: An iterator to the element after the erased elements.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ iterator erase(iterator b, iterator e)\r
+ { return tree_.erase(b, e); }\r
+\r
+ //! <b>Effects</b>: Erases all the elements with the given value.\r
+ //! \r
+ //! <b>Returns</b>: The number of erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size()) + this->count(value)).\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ size_type erase(const value_type &value)\r
+ { return tree_.erase(value); }\r
+\r
+ //! <b>Effects</b>: Erases all the elements that compare equal with\r
+ //! the given key and the given comparison functor.\r
+ //! \r
+ //! <b>Returns</b>: The number of erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).\r
+ //! \r
+ //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ template<class KeyType, class KeyValueCompare>\r
+ size_type erase(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.erase(key, comp); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases the element pointed to by pos. \r
+ //! Destroyer::operator()(pointer) is called for the removed element.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for erase element is constant time. \r
+ //! \r
+ //! <b>Returns</b>: An iterator to the element after the erased element.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators \r
+ //! to the erased elements.\r
+ template<class Destroyer>\r
+ iterator erase_and_destroy(iterator i, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(i, destroyer); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases the range pointed to by b end e.\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for erase range is at most \r
+ //! O(log(size() + N)), where N is the number of elements in the range.\r
+ //! \r
+ //! <b>Returns</b>: An iterator to the element after the erased elements.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators\r
+ //! to the erased elements.\r
+ template<class Destroyer>\r
+ iterator erase_and_destroy(iterator b, iterator e, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(b, e, destroyer); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases all the elements with the given value.\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ template<class Destroyer>\r
+ size_type erase_and_destroy(const value_type &value, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(value, destroyer); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases all the elements with the given key.\r
+ //! according to the comparison functor "comp".\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //!\r
+ //! <b>Returns</b>: The number of erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators\r
+ //! to the erased elements.\r
+ template<class KeyType, class KeyValueCompare, class Destroyer>\r
+ size_type erase_and_destroy(const KeyType& key, KeyValueCompare comp, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(key, comp, destroyer); }\r
+\r
+ //! <b>Effects</b>: Erases all the elements of the container.\r
+ //! \r
+ //! <b>Complexity</b>: Linear to the number of elements on the container.\r
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ void clear()\r
+ { return tree_.clear(); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //! \r
+ //! <b>Effects</b>: Erases all the elements of the container.\r
+ //! \r
+ //! <b>Complexity</b>: Linear to the number of elements on the container.\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ template<class Destroyer>\r
+ void clear_and_destroy(Destroyer destroyer)\r
+ { return tree_.clear_and_destroy(destroyer); }\r
+\r
+ //! <b>Effects</b>: Returns the number of contained elements with the given key\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal\r
+ //! to number of objects with the given key.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ size_type count(const value_type &value) const\r
+ { return tree_.find(value) != end(); }\r
+\r
+ //! <b>Effects</b>: Returns the number of contained elements with the same key\r
+ //! compared with the given comparison functor.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal\r
+ //! to number of objects with the given key.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ template<class KeyType, class KeyValueCompare>\r
+ size_type count(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.find(key, comp) != end(); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key is not less than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ iterator lower_bound(const value_type &value)\r
+ { return tree_.lower_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key according to the comparison functor is not less than k or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //! \r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ iterator lower_bound(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.lower_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Returns a const iterator to the first element whose\r
+ //! key is not less than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ const_iterator lower_bound(const value_type &value) const\r
+ { return tree_.lower_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose\r
+ //! key according to the comparison functor is not less than k or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //! \r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.lower_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key is greater than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ iterator upper_bound(const value_type &value)\r
+ { return tree_.upper_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key according to the comparison functor is greater than key or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ iterator upper_bound(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.upper_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key is greater than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ const_iterator upper_bound(const value_type &value) const\r
+ { return tree_.upper_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose\r
+ //! key according to the comparison functor is greater than key or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.upper_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds an iterator to the first element whose value is \r
+ //! "value" or end() if that element does not exist.\r
+ //!\r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ iterator find(const value_type &value)\r
+ { return tree_.find(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is \r
+ //! "key" according to the comparison functor or end() if that element \r
+ //! does not exist.\r
+ //!\r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ iterator find(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.find(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose value is \r
+ //! "value" or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ const_iterator find(const value_type &value) const\r
+ { return tree_.find(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose key is \r
+ //! "key" according to the comparison functor or end() if that element \r
+ //! does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ const_iterator find(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.find(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or\r
+ //! an empty range that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ std::pair<iterator,iterator> equal_range(const value_type &value)\r
+ { return tree_.equal_range(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k \r
+ //! according to the comparison functor or an empty range \r
+ //! that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.equal_range(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or\r
+ //! an empty range that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ std::pair<const_iterator, const_iterator>\r
+ equal_range(const value_type &value) const\r
+ { return tree_.equal_range(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k \r
+ //! according to the comparison functor or an empty range \r
+ //! that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ std::pair<const_iterator, const_iterator>\r
+ equal_range(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.equal_range(key, comp); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of\r
+ //! appropriate type. Otherwise the behavior is undefined.\r
+ //! \r
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set\r
+ //! that points to the value\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ static iterator current(value_type &value)\r
+ { return tree_type::current(value); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of\r
+ //! appropriate type. Otherwise the behavior is undefined.\r
+ //! \r
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the\r
+ //! set that points to the value\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ static const_iterator current(const value_type &value)\r
+ { return tree_type::current(value); }\r
+\r
+ friend bool operator==(const iset &x, const iset &y)\r
+ { return x.tree_ == y.tree_; }\r
+\r
+ friend bool operator<(const iset &x, const iset &y)\r
+ { return x.tree_ < y.tree_; }\r
+};\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator!=(const iset<V, P, C, S>& x, const iset<V, P, C, S>& y) \r
+{ return !(x==y); }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator>(const iset<V, P, C, S>& x, const iset<V, P, C, S>& y) \r
+{ return y < x; }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator<=(const iset<V, P, C, S>& x, const iset<V, P, C, S>& y) \r
+{ return !(y > x); }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator>=(const iset<V, P, C, S>& x, const iset<V, P, C, S>& y) \r
+{ return !(x < y); }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline void swap(iset<V, P, C, S>& x, iset<V, P, C, S>& y)\r
+{ x.swap(y); }\r
+\r
+//! The class template imultiset is an intrusive container, that mimics most of \r
+//! the interface of std::multiset as described in the C++ standard.\r
+//! \r
+//! The template parameter ValueTraits is called "value traits". It stores\r
+//! information and operations about the type to be stored\r
+//! in ilist and what type of hook has been chosen to include it in the list.\r
+//! The value_traits class is supplied by the appropriate hook as a template subtype \r
+//! called "value_traits".\r
+//!\r
+//! The template parameter Compare, provides a function object that can compare two \r
+//! element values as sort keys to determine their relative order in the set. \r
+//!\r
+//! If the user specifies ConstantTimeSize as "true", a member of type SizeType\r
+//! will be embedded in the class, that will keep track of the number of stored objects.\r
+//! This will allow constant-time O(1) size() member, instead of default O(N) size.\r
+template < class ValueTraits\r
+ , class Compare = std::less<typename ValueTraits::value_type>\r
+ , bool ConstantTimeSize = true\r
+ , class SizeType = std::size_t>\r
+class imultiset\r
+{\r
+ typedef detail::irbtree<ValueTraits, Compare, ConstantTimeSize, SizeType> tree_type;\r
+\r
+ //! This class is\r
+ //! non-copyable\r
+ imultiset (const imultiset&);\r
+\r
+ //! This class is\r
+ //! non-asignable\r
+ imultiset &operator =(const imultiset&);\r
+\r
+ typedef tree_type implementation_defined;\r
+\r
+ public:\r
+ typedef typename ValueTraits::value_type value_type;\r
+ typedef typename ValueTraits::pointer pointer;\r
+ typedef typename ValueTraits::const_pointer const_pointer;\r
+ typedef value_type& reference;\r
+ typedef const value_type& const_reference;\r
+ typedef SizeType size_type;\r
+ typedef typename std::iterator_traits\r
+ <pointer>::difference_type difference_type;\r
+ typedef value_type key_type;\r
+ typedef Compare value_compare;\r
+ typedef value_compare key_compare;\r
+ typedef typename implementation_defined::iterator iterator;\r
+ typedef typename implementation_defined::const_iterator const_iterator;\r
+ typedef typename implementation_defined::reverse_iterator reverse_iterator;\r
+ typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator;\r
+ typedef typename implementation_defined::insert_commit_data insert_commit_data;\r
+\r
+ private:\r
+ tree_type tree_;\r
+\r
+ public:\r
+ //! <b>Effects</b>: Constructs an empty multiset. \r
+ //! \r
+ //! <b>Complexity</b>: Constant. \r
+ //! \r
+ //! <b>Throws</b>: If value_traits::node_traits::node\r
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)\r
+ //! or the copy constructor/operator() of the Compare object throws. \r
+ imultiset(const Compare &cmp = Compare()) \r
+ : tree_(cmp)\r
+ {}\r
+\r
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. \r
+ //! cmp must be a comparison function that induces a strict weak ordering.\r
+ //! \r
+ //! <b>Effects</b>: Constructs an empty multiset and inserts elements from \r
+ //! [b, e).\r
+ //! \r
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using \r
+ //! comp and otherwise N * log N, where N is last Ā first.\r
+ //! \r
+ //! <b>Throws</b>: If value_traits::node_traits::node\r
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)\r
+ //! or the copy constructor/operator() of the Compare object throws. \r
+ template<class Iterator>\r
+ imultiset(Iterator b, Iterator e, const Compare &cmp = Compare())\r
+ : tree_(false, b, e, cmp)\r
+ {}\r
+\r
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the set \r
+ //! are not deleted (i.e. no destructors are called).\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size()) + size()) if it's a safe-mode or\r
+ //! auto-unlink value. Otherwise constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ ~imultiset() \r
+ {}\r
+\r
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ iterator begin()\r
+ { return tree_.begin(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_iterator begin() const\r
+ { return tree_.begin(); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ iterator end()\r
+ { return tree_.end(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_iterator end() const\r
+ { return tree_.end(); }\r
+\r
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the\r
+ //! reversed multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ reverse_iterator rbegin()\r
+ { return tree_.rbegin(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning\r
+ //! of the reversed multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_reverse_iterator rbegin() const\r
+ { return tree_.rbegin(); }\r
+\r
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end\r
+ //! of the reversed multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ reverse_iterator rend()\r
+ { return tree_.rend(); }\r
+\r
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end\r
+ //! of the reversed multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ const_reverse_iterator rend() const\r
+ { return tree_.rend(); }\r
+\r
+ //! <b>Effects</b>: Returns the key_compare object used by the multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: If key_compare copy-constructor throws.\r
+ key_compare key_comp() const\r
+ { return tree_.value_comp(); }\r
+\r
+ //! <b>Effects</b>: Returns the value_compare object used by the multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: If value_compare copy-constructor throws.\r
+ value_compare value_comp() const\r
+ { return tree_.value_comp(); }\r
+\r
+ //! <b>Effects</b>: Returns true is the container is empty.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ bool empty() const\r
+ { return tree_.empty(); }\r
+\r
+ //! <b>Effects</b>: Returns the number of elements stored in the multiset.\r
+ //! \r
+ //! <b>Complexity</b>: Linear to elements contained in *this if,\r
+ //! ConstantTimeSize is false. Constant-time otherwise.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ size_type size() const\r
+ { return tree_.size(); }\r
+\r
+ //! <b>Effects</b>: Swaps the contents of two multisets.\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: If the swap() call for the comparison functor\r
+ //! found using ADL throws. Strong guarantee.\r
+ void swap(imultiset& other)\r
+ { tree_.swap(other.tree_); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases all the elements from *this\r
+ //! calling Destroyer::operator()(pointer), clones all the \r
+ //! elements from src calling Cloner::operator()(const value_type &)\r
+ //! and inserts them on *this.\r
+ //!\r
+ //! If cloner throws, all cloned elements are unlinked and destroyed\r
+ //! calling Destroyer::operator()(pointer).\r
+ //! \r
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.\r
+ //! \r
+ //! <b>Throws</b>: If cloner throws. Basic guarantee.\r
+ template <class Cloner, class Destroyer>\r
+ void clone_from(const imultiset &src, Cloner cloner, Destroyer destroyer)\r
+ { tree_.clone_from(src.tree_, cloner, destroyer); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue\r
+ //! \r
+ //! <b>Effects</b>: Inserts value into the multiset.\r
+ //! \r
+ //! <b>Returns</b>: An iterator that points to the position where the new\r
+ //! element was inserted.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for insert element is at\r
+ //! most logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Strong guarantee.\r
+ //! \r
+ //! <b>Note</b>: Does not affect the validity of iterators and references.\r
+ //! No copy-constructors are called.\r
+ iterator insert(value_type &value)\r
+ { return tree_.insert_equal_upper_bound(value); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue\r
+ //! \r
+ //! <b>Effects</b>: Inserts x into the multiset, using pos as a hint to\r
+ //! where it will be inserted.\r
+ //! \r
+ //! <b>Returns</b>: An iterator that points to the position where the new\r
+ //! element was inserted.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized\r
+ //! constant time if t is inserted immediately before hint.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Strong guarantee.\r
+ //! \r
+ //! <b>Note</b>: Does not affect the validity of iterators and references.\r
+ //! No copy-constructors are called.\r
+ iterator insert(const_iterator hint, value_type &value)\r
+ { return tree_.insert_equal(hint, value); }\r
+\r
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue \r
+ //! of type value_type.\r
+ //! \r
+ //! <b>Effects</b>: Inserts a range into the multiset.\r
+ //! \r
+ //! <b>Returns</b>: An iterator that points to the position where the new\r
+ //! element was inserted.\r
+ //! \r
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the \r
+ //! size of the range. However, it is linear in N if the range is already sorted \r
+ //! by value_comp().\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Does not affect the validity of iterators and references.\r
+ //! No copy-constructors are called.\r
+ template<class Iterator>\r
+ void insert(Iterator b, Iterator e)\r
+ { tree_.insert_equal(b, e); }\r
+\r
+ //! <b>Effects</b>: Erases the element pointed to by pos. \r
+ //! \r
+ //! <b>Complexity</b>: Average complexity is constant time. \r
+ //! \r
+ //! <b>Returns</b>: An iterator to the element after the erased element.\r
+ //!\r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ iterator erase(iterator i)\r
+ { return tree_.erase(i); }\r
+\r
+ //! <b>Effects</b>: Erases the range pointed to by b end e. \r
+ //!\r
+ //! <b>Returns</b>: An iterator to the element after the erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for erase range is at most \r
+ //! O(log(size() + N)), where N is the number of elements in the range.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ iterator erase(iterator b, iterator e)\r
+ { return tree_.erase(b, e); }\r
+\r
+ //! <b>Effects</b>: Erases all the elements with the given value.\r
+ //! \r
+ //! <b>Returns</b>: The number of erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size() + this->count(value)).\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ size_type erase(const value_type &value)\r
+ { return tree_.erase(value); }\r
+\r
+ //! <b>Effects</b>: Erases all the elements that compare equal with\r
+ //! the given key and the given comparison functor.\r
+ //! \r
+ //! <b>Returns</b>: The number of erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ template<class KeyType, class KeyValueCompare>\r
+ size_type erase(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.erase(key, comp); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Returns</b>: An iterator to the element after the erased element.\r
+ //!\r
+ //! <b>Effects</b>: Erases the element pointed to by pos. \r
+ //! Destroyer::operator()(pointer) is called for the removed element.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for erase element is constant time. \r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators \r
+ //! to the erased elements.\r
+ template<class Destroyer>\r
+ iterator erase_and_destroy(iterator i, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(i, destroyer); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Returns</b>: An iterator to the element after the erased elements.\r
+ //!\r
+ //! <b>Effects</b>: Erases the range pointed to by b end e.\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //! \r
+ //! <b>Complexity</b>: Average complexity for erase range is at most \r
+ //! O(log(size() + N)), where N is the number of elements in the range.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators\r
+ //! to the erased elements.\r
+ template<class Destroyer>\r
+ iterator erase_and_destroy(iterator b, iterator e, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(b, e, destroyer); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases all the elements with the given value.\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //! \r
+ //! <b>Returns</b>: The number of erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size() + this->count(value)).\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ template<class Destroyer>\r
+ size_type erase_and_destroy(const value_type &value, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(value, destroyer); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //!\r
+ //! <b>Effects</b>: Erases all the elements with the given key.\r
+ //! according to the comparison functor "comp".\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //!\r
+ //! <b>Returns</b>: The number of erased elements.\r
+ //! \r
+ //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators\r
+ //! to the erased elements.\r
+ template<class KeyType, class KeyValueCompare, class Destroyer>\r
+ size_type erase_and_destroy(const KeyType& key, KeyValueCompare comp, Destroyer destroyer)\r
+ { return tree_.erase_and_destroy(key, comp, destroyer); }\r
+\r
+ //! <b>Effects</b>: Erases all the elements of the container.\r
+ //! \r
+ //! <b>Complexity</b>: Linear to the number of elements on the container.\r
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ void clear()\r
+ { return tree_.clear(); }\r
+\r
+ //! <b>Requires</b>: Destroyer::operator()(pointer) shouldn't throw.\r
+ //! \r
+ //! <b>Effects</b>: Erases all the elements of the container.\r
+ //! \r
+ //! <b>Complexity</b>: Linear to the number of elements on the container.\r
+ //! Destroyer::operator()(pointer) is called for the removed elements.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ //! \r
+ //! <b>Note</b>: Invalidates the iterators (but not the references)\r
+ //! to the erased elements. No destructors are called.\r
+ template<class Destroyer>\r
+ void clear_and_destroy(Destroyer destroyer)\r
+ { return tree_.clear_and_destroy(destroyer); }\r
+\r
+ //! <b>Effects</b>: Returns the number of contained elements with the same key\r
+ //! compared with the given comparison functor.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal\r
+ //! to number of objects with the given key.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ template<class KeyType, class KeyValueCompare>\r
+ size_type count(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.find(key, comp) != end(); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key is not less than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ iterator lower_bound(const value_type &value)\r
+ { return tree_.lower_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key according to the comparison functor is not less than k or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //! \r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ iterator lower_bound(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.lower_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Returns a const iterator to the first element whose\r
+ //! key is not less than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ const_iterator lower_bound(const value_type &value) const\r
+ { return tree_.lower_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose\r
+ //! key according to the comparison functor is not less than k or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //! \r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.lower_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key is greater than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ iterator upper_bound(const value_type &value)\r
+ { return tree_.upper_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key according to the comparison functor is greater than key or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ iterator upper_bound(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.upper_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Returns an iterator to the first element whose\r
+ //! key is greater than k or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ const_iterator upper_bound(const value_type &value) const\r
+ { return tree_.upper_bound(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose\r
+ //! key according to the comparison functor is greater than key or \r
+ //! end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.upper_bound(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds an iterator to the first element whose value is \r
+ //! "value" or end() if that element does not exist.\r
+ //!\r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ iterator find(const value_type &value)\r
+ { return tree_.find(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is \r
+ //! "key" according to the comparison functor or end() if that element \r
+ //! does not exist.\r
+ //!\r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ iterator find(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.find(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose value is \r
+ //! "value" or end() if that element does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ const_iterator find(const value_type &value) const\r
+ { return tree_.find(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose key is \r
+ //! "key" according to the comparison functor or end() if that element \r
+ //! does not exist.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ const_iterator find(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.find(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or\r
+ //! an empty range that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ std::pair<iterator,iterator> equal_range(const value_type &value)\r
+ { return tree_.equal_range(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k \r
+ //! according to the comparison functor or an empty range \r
+ //! that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp)\r
+ { return tree_.equal_range(key, comp); }\r
+\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or\r
+ //! an empty range that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If the internal Compare ordering function throws.\r
+ std::pair<const_iterator, const_iterator>\r
+ equal_range(const value_type &value) const\r
+ { return tree_.equal_range(value); }\r
+\r
+ //! <b>Requires</b>: comp must imply the same element order as\r
+ //! value_compare. Usually key is the part of the value_type\r
+ //! that is used in the ordering functor.\r
+ //!\r
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k \r
+ //! according to the comparison functor or an empty range \r
+ //! that indicates the position where those elements would be\r
+ //! if they there is no elements with key k.\r
+ //! \r
+ //! <b>Complexity</b>: Logarithmic.\r
+ //! \r
+ //! <b>Throws</b>: If comp ordering function throws.\r
+ //!\r
+ //! <b>Note</b>: This function is used when constructing a value_type\r
+ //! is expensive and the value_type can be compared with a cheaper\r
+ //! key type. Usually this key is part of the value_type.\r
+ template<class KeyType, class KeyValueCompare>\r
+ std::pair<const_iterator, const_iterator>\r
+ equal_range(const KeyType& key, KeyValueCompare comp) const\r
+ { return tree_.equal_range(key, comp); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of\r
+ //! appropriate type. Otherwise the behavior is undefined.\r
+ //! \r
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set\r
+ //! that points to the value\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ static iterator current(value_type &value)\r
+ { return tree_type::current(value); }\r
+\r
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of\r
+ //! appropriate type. Otherwise the behavior is undefined.\r
+ //! \r
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the\r
+ //! set that points to the value\r
+ //! \r
+ //! <b>Complexity</b>: Constant.\r
+ //! \r
+ //! <b>Throws</b>: Nothing.\r
+ static const_iterator current(const value_type &value)\r
+ { return tree_type::current(value); }\r
+\r
+ friend bool operator==(const imultiset &x, const imultiset &y)\r
+ { return x.tree_ == y.tree_; }\r
+\r
+ friend bool operator<(const imultiset &x, const imultiset &y)\r
+ { return x.tree_ < y.tree_; }\r
+};\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator!=(const imultiset<V, P, C, S>& x, const imultiset<V, P, C, S>& y) \r
+{ return !(x==y); }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator>(const imultiset<V, P, C, S>& x, const imultiset<V, P, C, S>& y) \r
+{ return y < x; }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator<=(const imultiset<V, P, C, S>& x, const imultiset<V, P, C, S>& y) \r
+{ return !(y > x); }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline bool operator>=(const imultiset<V, P, C, S>& x, const imultiset<V, P, C, S>& y) \r
+{ return !(x < y); }\r
+\r
+template <class V, class P, bool C, class S>\r
+inline void swap(imultiset<V, P, C, S>& x, imultiset<V, P, C, S>& y)\r
+{ x.swap(y); }\r
+\r
+} //namespace intrusive \r
+} //namespace boost \r
+\r
+#include "detail/config_end.hpp"\r
+\r
+#endif //BOOST_INTRUSIVE_ISET_HPP\r