...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
"boost/multi_index/ordered_index_fwd.hpp"
synopsis"boost/multi_index/ordered_index.hpp"
synopsis
"boost/multi_index/ordered_index_fwd.hpp"
synopsisnamespace boost{ namespace multi_index{ // index specifiers ordered_unique and ordered_non_unique template<consult ordered_unique reference for arguments> struct ordered_unique; template<consult ordered_non_unique reference for arguments> struct ordered_non_unique; // indices namespace detail{ template<implementation defined> class index name is implementation defined; } // namespace boost::multi_index::detail } // namespace boost::multi_index } // namespace boost
ordered_index_fwd.hpp
provides forward declarations for index specifiers
ordered_unique
and ordered_non_unique
and
their associated ordered index classes.
"boost/multi_index/ordered_index.hpp"
synopsis#include <initializer_list> namespace boost{ namespace multi_index{ // index specifiers ordered_unique and ordered_non_unique template<consult ordered_unique reference for arguments> struct ordered_unique; template<consult ordered_non_unique reference for arguments> struct ordered_non_unique; // indices namespace detail{ template<implementation defined> class index class name implementation defined; // index comparison: // OP is any of ==,<,!=,>,>=,<= template<arg set 1,arg set 2> bool operator OP( const index class name<arg set 1>& x,const index class name<arg set 2>& y); // index specialized algorithms: template<implementation defined> void swap(index class name& x,index class name& y); } // namespace boost::multi_index::detail } // namespace boost::multi_index } // namespace boost
ordered_unique
and ordered_non_unique
These index specifiers allow
for insertion of ordered indices without and with
allowance of duplicate elements, respectively. The syntax of ordered_unique
and ordered_non_unique
coincide, thus we describe them in a grouped manner.
ordered_unique
and ordered_non_unique
can be instantiated in
two different forms, according to whether a tag list for the index is provided or not:
template< typename KeyFromValue, typename Compare=std::less<KeyFromValue::result_type> > struct (ordered_unique | ordered_non_unique); template< typename TagList, typename KeyFromValue, typename Compare=std::less<KeyFromValue::result_type> > struct (ordered_unique | ordered_non_unique);
If provided, TagList
must be an instantiation of the class template
tag
.
The template arguments are used by the corresponding index implementation,
refer to the ordered indices reference section for further
explanations on their acceptable type values.
An ordered index provides a set-like interface to the underlying heap of
elements contained in a multi_index_container
. An ordered index is
particularized according to a given
Key Extractor
that retrieves keys from elements of multi_index_container
and a comparison
predicate.
There are two variants of ordered indices: unique, which do not allow duplicate elements (with respect to its associated comparison predicate) and non-unique, which accept those duplicates. The interface of these two variants is the same, so they are documented together, with minor differences explicitly stated when they exist.
Except where noted or if the corresponding interface does not exist, ordered indices (both unique and non-unique) satisfy the C++ requirements for associative containers at [associative.reqmts] (supporting unique and equivalent keys, respectively.) Iterators (including to the end of the index) and pointers and references to an element remain valid during the lifetime of the associated container (which can change upon swapping), or until the referred-to element is erased or extracted; pointers and references to an extracted element, but not so for iterators, become valid again once the element is re-inserted. We only provide descriptions of those types and operations that do not exactly conform to or are not mandated by the standard requirements.
namespace boost{ namespace multi_index{ implementation defined unbounded; // see range() namespace detail{ template<implementation defined: dependent on types Value, Allocator, TagList, KeyFromValue, Compare> class name is implementation defined { public: // types: typedef typename KeyFromValue::result_type key_type; typedef Value value_type; typedef KeyFromValue key_from_value; typedef Compare key_compare; typedef implementation defined value_compare; typedef boost::tuple<key_from_value,key_compare> ctor_args; typedef TagList tag_list; typedef Allocator allocator_type; typedef typename Allocator::reference reference; typedef typename Allocator::const_reference const_reference; typedef implementation defined iterator; typedef implementation defined const_iterator; typedef implementation defined size_type; typedef implementation defined difference_type; typedef typename Allocator::pointer pointer; typedef typename Allocator::const_pointer const_pointer; typedef equivalent to std::reverse_iterator<iterator> reverse_iterator; typedef equivalent to std::reverse_iterator<const_iterator> const_reverse_iterator; typedef same as owning container node_type; typedef following [container.insert.return] spec insert_return_type; // construct/copy/destroy: index class name& operator=(const index class name& x); index class name& operator=(std::initializer_list<value_type> list); allocator_type get_allocator()const noexcept; // iterators: iterator begin()noexcept; const_iterator begin()const noexcept; iterator end()noexcept; const_iterator end()const noexcept; reverse_iterator rbegin()noexcept; const_reverse_iterator rbegin()const noexcept; reverse_iterator rend()noexcept; const_reverse_iterator rend()const noexcept; const_iterator cbegin()const noexcept; const_iterator cend()const noexcept; const_reverse_iterator crbegin()const noexcept; const_reverse_iterator crend()const noexcept; iterator iterator_to(const value_type& x); const_iterator iterator_to(const value_type& x)const; // capacity: bool empty()const noexcept; size_type size()const noexcept; size_type max_size()const noexcept; // modifiers: template<typename... Args> std::pair<iterator,bool> emplace(Args&&... args); template <typename... Args> iterator emplace_hint(iterator position,Args&&... args); std::pair<iterator,bool> insert(const value_type& x); std::pair<iterator,bool> insert(value_type&& x); iterator insert(iterator position,const value_type& x); iterator insert(iterator position,value_type&& x); template<typename InputIterator> void insert(InputIterator first,InputIterator last); void insert(std::initializer_list<value_type> list); insert_return_type insert(node_type&& nh); iterator insert(const_iterator position,node_type&& nh); node_type extract(const_iterator position); node_type extract(const key_type& x); iterator erase(iterator position); size_type erase(const key_type& x); iterator erase(iterator first,iterator last); bool replace(iterator position,const value_type& x); bool replace(iterator position,value_type&& x); template<typename Modifier> bool modify(iterator position,Modifier mod); template<typename Modifier,typename Rollback> bool modify(iterator position,Modifier mod,Rollback back); template<typename Modifier> bool modify_key(iterator position,Modifier mod); template<typename Modifier,typename Rollback> bool modify_key(iterator position,Modifier mod,Rollback back); void swap(index class name& x); void clear()noexcept; // observers: key_from_value key_extractor()const; key_compare key_comp()const; value_compare value_comp()const; // set operations: template<typename CompatibleKey> iterator find(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> iterator find( const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> size_type count(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> size_type count(const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> iterator lower_bound(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> iterator lower_bound( const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> iterator upper_bound(const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> iterator upper_bound( const CompatibleKey& x,const CompatibleCompare& comp)const; template<typename CompatibleKey> std::pair<iterator,iterator> equal_range( const CompatibleKey& x)const; template<typename CompatibleKey,typename CompatibleCompare> std::pair<iterator,iterator> equal_range( const CompatibleKey& x,const CompatibleCompare& comp)const; // range: template<typename LowerBounder,typename UpperBounder> std::pair<iterator,iterator> range( LowerBounder lower,UpperBounder upper)const; }; // index comparison: template<arg set 1,arg set 2> bool operator==( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return x.size()==y.size()&&std::equal(x.begin(),x.end(),y.begin()); } template<arg set 1,arg set 2> bool operator<( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()); } template<arg set 1,arg set 2> bool operator!=( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return !(x==y); } template<arg set 1,arg set 2> bool operator>( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return y<x; } template<arg set 1,arg set 2> bool operator>=( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return !(x<y); } template<arg set 1,arg set 2> bool operator<=( const index class name<arg set 1>& x, const index class name<arg set 2>& y) { return !(x>y); } // index specialized algorithms: template<implementation defined> void swap(index class name& x,index class name& y); } // namespace boost::multi_index::detail } // namespace boost::multi_index } // namespace boost
Here and in the descriptions of operations of ordered indices, we adopt the scheme outlined in the complexity signature section. The complexity signature of ordered indices is:
c(n)=n*log(n)
,i(n)=log(n)
,h(n)=1
(constant) if the hint element
is immediately after the point of insertion, h(n)=log(n)
otherwise,d(n)=1
(amortized constant),r(n)=1
(constant) if the element position does not
change, r(n)=log(n)
otherwise,m(n)=1
(constant) if the element position does not
change, m(n)=log(n)
otherwise.Ordered indices are instantiated internally to multi_index_container
and
specified by means of indexed_by
with index specifiers ordered_unique
and ordered_non_unique
. Instantiations are dependent on the
following types:
Value
from multi_index_container
,Allocator
from multi_index_container
,TagList
from the index specifier (if provided, otherwise tag<>
is assumed),KeyFromValue
from the index specifier,Compare
from the index specifier.TagList
must be an instantiation of
tag
. The type KeyFromValue
,
which determines the mechanism for extracting a key from Value
,
must be a model of
Key Extractor
from Value
. Compare
is a
CopyConstructible
binary predicate inducing a strict weak order
on elements of KeyFromValue::result_type
.
As explained in the index concepts section, indices do not have public constructors or destructors. Assignment, on the other hand, is provided.
index class name& operator=(const index class name& x);
Effects:wherea=b;a
andb
are themulti_index_container
objects to which*this
andx
belong, respectively.
Returns:*this
.
index class name& operator=(std::initializer_list<value_type> list);
Effects:wherea=list;a
is themulti_index_container
object to which*this
belongs.
Returns:*this
.
iterator iterator_to(const value_type& x);
const_iterator iterator_to(const value_type& x)const;
Requires:x
is a reference to an element of the container.
Returns: An iterator tox
.
Complexity: Constant.
Exception safety:nothrow
.
template<typename... Args>
std::pair<iterator,bool> emplace(Args&&... args);
Requires:value_type
isEmplaceConstructible
intomulti_index_container
fromargs
.
Effects: Inserts avalue_type
object constructed withstd::forward<Args>(args)...
into themulti_index_container
to which the index belongs ifReturns: The return value is a pair
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the
multi_index_container
.p
.p.second
istrue
if and only if insertion took place. On successful insertion,p.first
points to the element inserted; otherwise,p.first
points to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
Complexity:O(I(n))
.
Exception safety: Strong.
template<typename... Args>
iterator emplace_hint(iterator position, Args&&... args);
Requires:value_type
isEmplaceConstructible
intomulti_index_container
fromargs
.position
is a valid iterator of the index.
Effects: Inserts avalue_type
object constructed withstd::forward<Args>(args)...
into themulti_index_container
to which the index belongs if
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the
multi_index_container
.position
is used as a hint to improve the efficiency of the operation. If successful, insertion happens as close as possible to the location just prior toposition
.
Returns: On successful insertion, an iterator to the newly inserted element. Otherwise, an iterator to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
Complexity:O(H(n))
.
Exception safety: Strong.
std::pair<iterator,bool> insert(const value_type& x);
std::pair<iterator,bool> insert(value_type&& x);
Requires (first version):value_type
isCopyInsertable
intomulti_index_container
.
Requires (second version):value_type
isMoveInsertable
intomulti_index_container
.
Effects: Insertsx
into themulti_index_container
to which the index belongs ifReturns: The return value is a pair
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the
multi_index_container
.p
.p.second
istrue
if and only if insertion took place. On successful insertion,p.first
points to the element inserted; otherwise,p.first
points to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
Complexity:O(I(n))
.
Exception safety: Strong.
iterator insert(iterator position,const value_type& x);
iterator insert(iterator position,value_type&& x);
Requires (first version):value_type
isCopyInsertable
intomulti_index_container
.position
is a valid iterator of the index.
Requires (second version):value_type
isMoveInsertable
intomulti_index_container
.position
is a valid iterator of the index.
Effects: Insertsx
into themulti_index_container
to which the index belongs if
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the
multi_index_container
.position
is used as a hint to improve the efficiency of the operation. If successful, insertion happens as close as possible to the location just prior toposition
.
Returns: On successful insertion, an iterator to the newly inserted element. Otherwise, an iterator to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
Complexity:O(H(n))
.
Exception safety: Strong.
template<typename InputIterator>
void insert(InputIterator first,InputIterator last);
Requires:InputIterator
is an input iterator.value_type
isEmplaceConstructible
intomulti_index_container
from*first
.first
andlast
are not iterators into any index of themulti_index_container
to which this index belongs.last
is reachable fromfirst
.
Effects: For each element of [first
,last
), in this order, inserts it into themulti_index_container
to which this index belongs ifComplexity:
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the
multi_index_container
.O(m*H(n+m))
, wherem
is the number of elements in [first
,last
).
Exception safety: Basic.
void insert(std::initializer_list<value_type> list);
Effects:insert(list.begin(),list.end());
insert_return_type insert(node_type&& nh);
Requires:nh.empty() || get_allocator()==nh.get_allocator()
.
Effects: Does nothing ifnh
is empty; otherwise, inserts the node owned bynh
into themulti_index_container
to which the index belongs ifPostconditions:
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the
multi_index_container
.nh
is empty.
Returns: A valuep
of typeinsert_return_type
. Ifnh
is empty,p.position
isend()
,p.inserted
isfalse
andp.node
is empty; on successful insertion,p.position
points to the element inserted,p.inserted
istrue
andp.node
is empty; if the insertion failed,p.position
points to an element that caused the insertion to be banned,p.inserted
isfalse
andp.node
owns the original node. Note that more than one element can be causing insertion not to be allowed.
Complexity:O(I(n))
.
Exception safety: Strong. If an exception is thrown,nh
is not changed.
iterator insert(const_iterator position,node_type&& nh);
Requires:nh.empty() || get_allocator()==nh.get_allocator()
.position
is a valid iterator of the index.
Effects: Does nothing ifnh
is empty; otherwise, inserts the node owned bynh
into themulti_index_container
to which the index belongs if
- the index is non-unique OR no other element exists with equivalent key,
- AND insertion is allowed by all other indices of the
multi_index_container
.position
is used as a hint to improve the efficiency of the operation. If successful, insertion happens as close as possible to the location just prior toposition
.
Postconditions:nh
is empty if insertion succeeds, and is not changed otherwise.
Returns:end()
ifnh
is empty. On successful insertion, an iterator to the newly inserted element; otherwise, an iterator to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
Complexity:O(H(n))
.
Exception safety: Strong. If an exception is thrown,nh
is not changed.
node_type extract(const_iterator position);
Requires:position
is a valid dereferenceable iterator of the index.
Effects: Extracts the node of the element pointed to byposition
.
Returns: A node handle owning the extracted node.
Complexity:O(D(n))
.
Exception safety:nothrow
.
node_type extract(const key_type& x);
Effects: Extracts the node of the first element with key equivalent tox
, if there is any.
Returns: A node handle owning the extracted node, or empty otherwise.
Complexity:O(log(n) + D(n))
.
Exception safety: Strong.
iterator erase(iterator position);
Requires:position
is a valid dereferenceable iterator of the index.
Effects: Deletes the element pointed to byposition
.
Returns: An iterator pointing to the element immediately following the one that was deleted, orend()
if no such element exists.
Complexity:O(D(n))
.
Exception safety:nothrow
.
size_type erase(const key_type& x);
Effects: Deletes the elements with key equivalent tox
.
Returns: Number of elements deleted.
Complexity:O(log(n) + m*D(n))
, wherem
is the number of elements deleted.
Exception safety: Basic.
iterator erase(iterator first,iterator last);
Requires: [first
,last
) is a valid range of the index.
Effects: Deletes the elements in [first
,last
).
Returns:last
.
Complexity:O(log(n) + m*D(n))
, wherem
is the number of elements in [first
,last
).
Exception safety:nothrow
.
bool replace(iterator position,const value_type& x);
bool replace(iterator position,value_type&& x);
Requires (first version):value_type
isCopyAssignable
.position
is a valid dereferenceable iterator of the index.
Requires (second version):value_type
isMoveAssignable
.position
is a valid dereferenceable iterator of the index.
Effects: Assigns the valuex
to the element pointed to byposition
into themulti_index_container
to which the index belongs if, for the valuex
Postconditions: Validity of
- the index is non-unique OR no other element exists (except possibly
*position
) with equivalent key,- AND replacing is allowed by all other indices of the
multi_index_container
.position
is preserved in all cases. If the key of the new value is equivalent to that of the replaced value, the position of the element does not change.
Returns:true
if the replacement took place,false
otherwise.
Complexity:O(R(n))
.
Exception safety: Strong. If an exception is thrown by some user-provided operation themulti_index_container
to which the index belongs remains in its original state.
template<typename Modifier> bool modify(iterator position,Modifier mod);
Requires:mod
is a unary function object accepting arguments of typevalue_type&
.position
is a valid dereferenceable iterator of the index. The execution ofmod(e)
, wheree
is the element pointed to byposition
, does not invoke any operation of themulti_index_container
aftere
is directly modified or, before modification, if the operation would invalidateposition
.
Effects: Callsmod(e)
wheree
is the element pointed to byposition
and rearranges*position
into all the indices of themulti_index_container
. Rearrangement is successful ifIf the rearrangement fails, the element is erased.
- the index is non-unique OR no other element exists with equivalent key,
- AND rearrangement is allowed by all other indices of the
multi_index_container
.
Postconditions: Validity ofposition
is preserved if the operation succeeds. If the key of the modified value is equivalent to that of the original value, the position of the element does not change.
Returns:true
if the operation succeeded,false
otherwise.
Complexity:O(M(n))
.
Exception safety: Basic. If an exception is thrown by some user-provided operation (includingmod
), then the element pointed to byposition
is erased.
template<typename Modifier,typename Rollback>
bool modify(iterator position,Modifier mod,Rollback back);
Requires:mod
andback
are unary function objects accepting arguments of typevalue_type&
.position
is a valid dereferenceable iterator of the index. The execution ofmod(e)
, wheree
is the element pointed to byposition
, does not invoke any operation of themulti_index_container
aftere
is directly modified or, before modification, if the operation would invalidateposition
.back(e)
does not invoke any operation of themulti_index_container
.
Effects: Callsmod(e)
wheree
is the element pointed to byposition
and tries to rearrange*position
into all the indices of themulti_index_container
. Rearrangement is successful ifIf the rearrangement fails,
- the index is non-unique OR no other element exists with equivalent key,
- AND rearrangement is allowed by all other indices of the
multi_index_container
.back(e)
is invoked: if the resulting value ofe
is consistent with its original position and constraints in all indices, the element is kept, otherwise it is erased.
Postconditions: Validity ofposition
is preserved except if the element is erased under the conditions described below. If the key of the modified value is equivalent to that of the original value, the position of the element does not change.
Returns:true
if the operation succeeded,false
otherwise.
Complexity:O(M(n))
.
Exception safety: Strong, except ifmod
orback
throw an exception orback(e)
fails to properly restore the element or there is a throwing user-provided operation after invokingback(e)
, in which cases the modified element is erased. Ifback
throws inside the handling code executing after some other user-provided operation has thrown, it is the exception generated byback
that is rethrown.
template<typename Modifier> bool modify_key(iterator position,Modifier mod);
Requires:key_from_value
is a read/writeKey Extractor
fromvalue_type
.mod
is a unary function object accepting arguments of typekey_type&
.position
is a valid dereferenceable iterator of the index. The execution ofmod(k)
, wherek
is the key of the element pointed to byposition
, does not invoke any operation of themulti_index_container
afterk
is directly modified or, before modification, if the operation would invalidateposition
.
Effects: Equivalent tomodify(position,mod')
, withmod'
defined in such a way thatmod'(x)
is the same asmod(key(x))
, wherekey
is the internalKeyFromValue
object of the index.
template<typename Modifier,typename Rollback>
bool modify_key(iterator position,Modifier mod,Rollback back);
Requires:key_from_value
is a read/writeKey Extractor
fromvalue_type
.mod
andback
are unary function objects accepting arguments of typekey_type&
.position
is a valid dereferenceable iterator of the index. The execution ofmod(k)
, wherek
is the key of the element pointed to byposition
, does not invoke any operation of themulti_index_container
afterk
is directly modified or, before modification, if the operation would invalidateposition
.back(k)
does not invoke any operation of themulti_index_container
.
Effects: Equivalent tomodify(position,mod',back')
, withmod'
andback
defined in such a way thatmod'(x)
is the same asmod(key(x))
andback'(x)
is the same asback(key(x))
, wherekey
is the internalKeyFromValue
object of the index.
Apart from standard key_comp
and value_comp
,
ordered indices have a member function for retrieving the internal key extractor
used.
key_from_value key_extractor()const;
Returns a copy of thekey_from_value
object used to construct the index.
Complexity: Constant.
Ordered indices provide the full lookup functionality required by
[associative.reqmts], namely find
,
count
, lower_bound
, upper_bound
and equal_range
. Additionally, these member functions are
templatized to allow for non-standard arguments, so extending
the types of search operations allowed. The kind of arguments permissible
when invoking the lookup member functions is defined by the following
concept.
Consider a binary predicate Compare
inducing a strict
weak order over values of type Key
. A pair of types (CompatibleKey
,
CompatibleCompare
) is said to be a compatible extension
of Compare
if
CompatibleCompare
is a binary predicate over (Key
,
CompatibleKey
),CompatibleCompare
is a binary predicate over (CompatibleKey
,
Key
),c_comp(ck,k1)
then !c_comp(k1,ck)
,!c_comp(ck,k1)
and !comp(k1,k2)
then
!c_comp(ck,k2)
,!c_comp(k1,ck)
and !comp(k2,k1)
then
!c_comp(k2,ck)
,c_comp
of type CompatibleCompare
,
comp
of type Compare
, ck
of type
CompatibleKey
and k1
, k2
of type
Key
.
Additionally, a type CompatibleKey
is said to be a
compatible key of Compare
if (CompatibleKey
,
Compare
) is a compatible extension of Compare
.
This implies that Compare
, as well as being a strict
weak ordering, accepts arguments of type CompatibleKey
,
which usually means it has several overloads of operator()
.
In the context of a compatible extension or a compatible key, the expressions "equivalent", "less than" and "greater than" take on their obvious interpretations.
template<typename CompatibleKey> iterator find(const CompatibleKey& x)const;
Requires:CompatibleKey
is a compatible key ofkey_compare
.
Effects: Returns a pointer to an element whose key is equivalent tox
, orend()
if such an element does not exist.
Complexity:O(log(n))
.
template<typename CompatibleKey,typename CompatibleCompare>
iterator find(const CompatibleKey& x,const CompatibleCompare& comp)const;
Requires: (CompatibleKey
,CompatibleCompare
) is a compatible extension ofkey_compare
.
Effects: Returns a pointer to an element whose key is equivalent tox
, orend()
if such an element does not exist.
Complexity:O(log(n))
.
template<typename CompatibleKey> size_type
count(const CompatibleKey& x)const;
Requires:CompatibleKey
is a compatible key ofkey_compare
.
Effects: Returns the number of elements with key equivalent tox
.
Complexity:O(log(n) + count(x))
.
template<typename CompatibleKey,typename CompatibleCompare>
size_type count(const CompatibleKey& x,const CompatibleCompare& comp)const;
Requires: (CompatibleKey
,CompatibleCompare
) is a compatible extension ofkey_compare
.
Effects: Returns the number of elements with key equivalent tox
.
Complexity:O(log(n) + count(x,comp))
.
template<typename CompatibleKey>
iterator lower_bound(const CompatibleKey& x)const;
Requires:CompatibleKey
is a compatible key ofkey_compare
.
Effects: Returns an iterator pointing to the first element with key not less thanx
, orend()
if such an element does not exist.
Complexity:O(log(n))
.
template<typename CompatibleKey,typename CompatibleCompare>
iterator lower_bound(const CompatibleKey& x,const CompatibleCompare& comp)const;
Requires: (CompatibleKey
,CompatibleCompare
) is a compatible extension ofkey_compare
.
Effects: Returns an iterator pointing to the first element with key not less thanx
, orend()
if such an element does not exist.
Complexity:O(log(n))
.
template<typename CompatibleKey>
iterator upper_bound(const CompatibleKey& x)const;
Requires:CompatibleKey
is a compatible key ofkey_compare
.
Effects: Returns an iterator pointing to the first element with key greater thanx
, orend()
if such an element does not exist.
Complexity:O(log(n))
.
template<typename CompatibleKey,typename CompatibleCompare>
iterator upper_bound(const CompatibleKey& x,const CompatibleCompare& comp)const;
Requires: (CompatibleKey
,CompatibleCompare
) is a compatible extension ofkey_compare
.
Effects: Returns an iterator pointing to the first element with key greater thanx
, orend()
if such an element does not exist.
Complexity:O(log(n))
.
template<typename CompatibleKey>
std::pair<iterator,iterator> equal_range(
const CompatibleKey& x)const;
Requires:CompatibleKey
is a compatible key ofkey_compare
.
Effects: Equivalent tomake_pair(lower_bound(x),upper_bound(x))
.
Complexity:O(log(n))
.
template<typename CompatibleKey,typename CompatibleCompare>
std::pair<iterator,iterator> equal_range(
const CompatibleKey& x,const CompatibleCompare& comp)const;
Requires: (CompatibleKey
,CompatibleCompare
) is a compatible extension ofkey_compare
.
Effects: Equivalent tomake_pair(lower_bound(x,comp),upper_bound(x,comp))
.
Complexity:O(log(n))
.
The member function range
is not defined for sorted associative
containers, but ordered indices provide it as a convenient utility. A range
or interval is defined by two conditions for the lower and upper bounds, which
are modeled after the following concepts.
Consider a binary predicate Compare
inducing a strict
weak order over values of type Key
. A type LowerBounder
is said to be
a lower bounder of Compare
if
LowerBounder
is a predicate over Key
,lower(k1)
and !comp(k2,k1)
then
lower(k2)
,lower
of type LowerBounder
,
comp
of type Compare
, and k1
,
k2
of type Key
. Similarly, an upper bounder
is a type UpperBounder
such that
UpperBounder
is a predcate over Key
,upper(k1)
and !comp(k1,k2)
then
upper(k2)
,upper
of type UpperBounder
,
comp
of type Compare
, and k1
,
k2
of type Key
.
template<typename LowerBounder,typename UpperBounder>
std::pair<iterator,iterator> range(
LowerBounder lower,UpperBounder upper)const;
Requires:LowerBounder
andUpperBounder
are a lower and upper bounder ofkey_compare
, respectively.
Effects: Returns a pair of iterators pointing to the beginning and one past the end of the subsequence of elements satisfyinglower
andupper
simultaneously. If no such elements exist, the iterators both point to the first element satisfyinglower
, or else are equal toend()
if this latter element does not exist.
Complexity:O(log(n))
.
Variants: In place oflower
orupper
(or both), the singular valueboost::multi_index::unbounded
can be provided. This acts as a predicate which all values of typekey_type
satisfy.
Indices cannot be serialized on their own, but only as part of the
multi_index_container
into which they are embedded. In describing
the additional preconditions and guarantees associated to ordered indices
with respect to serialization of their embedding containers, we
use the concepts defined in the multi_index_container
serialization section.
multi_index_container
m
to an
output archive (XML archive) ar
.
Requires: No additional requirements to those imposed by the container.Operation: loading of a
multi_index_container
m'
from an
input archive (XML archive) ar
.
Requires: Additionally to the general requirements,Operation: saving of anvalue_comp()
must be serialization-compatible withm.get<i>().value_comp()
, wherei
is the position of the ordered index in the container.
Postconditions: On successful loading, each of the elements of [begin()
,end()
) is a restored copy of the corresponding element in [m.get<i>().begin()
,m.get<i>().end()
).
iterator
or const_iterator
it
to an output archive (XML archive) ar
.
Requires:Operation: loading of anit
is a valid iterator of the index. The associatedmulti_index_container
has been previously saved.
iterator
or const_iterator
it'
from an input archive (XML archive) ar
.
Postconditions: On successful loading, ifit
was dereferenceable then*it'
is the restored copy of*it
, otherwiseit'==end()
.
Note: It is allowed thatit
be aconst_iterator
and the restoredit'
aniterator
, or viceversa.
Revised May 9th 2020
© Copyright 2003-2020 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)