Boost.MultiIndex Random access indices reference"boost/multi_index/random_access_index_fwd.hpp" synopsis"boost/multi_index/random_access_index.hpp" synopsis
"boost/multi_index/random_access_index_fwd.hpp" synopsisnamespace boost{ namespace multi_index{ // random_access index specifier template<typename TagList=tag<> > struct random_access; // indices namespace detail{ template<implementation defined> class index class name implementation defined; } // namespace boost::multi_index::detail } // namespace boost::multi_index } // namespace boost
random_access_index_fwd.hpp provides forward declarations for the
random_access index specifier and
its associated random access index class.
"boost/multi_index/random_access_index.hpp" synopsis#include <initializer_list> namespace boost{ namespace multi_index{ // random_access index specifier template<typename TagList=tag<> > struct random_access; // 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
random_access index specifier
This index specifier allows for insertion of a random access index.
template<typename TagList=tag<> > struct random_access;
If provided, TagList must be an instantiation of
tag.
Random access indices are free-order sequences with constant time
positional access and random access iterators. Elements in a
random access index are by default sorted according to their order of
insertion: this means that new elements inserted through a different index
of the multi_index_container are appended to the end of the
random access index; additionally, facilities are provided
for further rearrangement of the elements. The public interface of
random access indices includes that of
sequenced indices, with differences in
the complexity of the operations, plus extra operations for
positional access (operator[] and at()) and
for capacity handling.
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) regardless of the capacity status, 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.
Except where noted or if the corresponding interface does not exist, random access
indices verify the same container requirements as std::vector
plus the requirements for std::list specific list operations at
[list.ops]. Some of the most important differences with respect to
std::vector are:
data member functions.
std::vector.
std::vector, insertions into a random access index
may fail due to clashings with other indices. This alters the semantics
of the operations provided with respect to their analogues in
std::vector.
replace and
modify member functions.
push_front and pop_front are provided for
compatibility with sequenced indices, even though they take linear time to execute.
namespace boost{ namespace multi_index{ namespace detail{ template<implementation defined: dependent on types Value, Allocator, TagList> class name is implementation defined { public: // types: typedef Value value_type; typedef boost::tuples::null_type ctor_args; typedef TagList tag_list; typedef Allocator allocator_type; typedef typename allocator_type::reference reference; typedef typename allocator_type::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_type::pointer pointer; typedef typename allocator_type::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); template <class InputIterator> void assign(InputIterator first,InputIterator last); void assign(std::initializer_list<value_type> list) void assign(size_type n,const value_type& value); 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; size_type capacity()const noexcept; void reserve(size_type m); void shrink_to_fit(); void resize(size_type n); void resize(size_type n,const value_type& x); // access: const_reference operator[](size_type n)const; const_reference at(size_type n)const; const_reference front()const; const_reference back()const; // modifiers: template<typename... Args> std::pair<iterator,bool> emplace_front(Args&&... args); std::pair<iterator,bool> push_front(const value_type& x); std::pair<iterator,bool> push_front(value_type&& x); void pop_front(); template<typename... Args> std::pair<iterator,bool> emplace_back(Args&&... args); std::pair<iterator,bool> push_back(const value_type& x); std::pair<iterator,bool> push_back(value_type&& x); void pop_back(); template<typename... Args> std::pair<iterator,bool> emplace(iterator position,Args&&... args); std::pair<iterator,bool> insert(iterator position,const value_type& x); std::pair<iterator,bool> insert(iterator position,value_type&& x); void insert(iterator position,size_type m,const value_type& x); template<typename InputIterator> void insert(iterator position,InputIterator first,InputIterator last); void insert(iterator position,std::initializer_list<value_type> list); insert_return_type insert(const_iterator position,node_type&& nh); node_type extract(const_iterator position); iterator erase(iterator position); 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); void swap(index class name& x); void clear()noexcept; // list operations: template<typename Index> void splice(const_iterator position,Index&& x); template<typename Index> std::pair<iterator,bool> splice( const_iterator position,Index&& x, typename std::remove_reference_t<Index>::const_iterator i); template<typename Index> void splice( const_iterator position,Index&& x, typename std::remove_reference_t<Index>::const_iterator first, typename std::remove_reference_t<Index>::const_iterator last); void remove(const value_type& value); template<typename Predicate> void remove_if(Predicate pred); void unique(); template <class BinaryPredicate> void unique(BinaryPredicate binary_pred); void merge(index class name& x); template <typename Compare> void merge(index class name& x,Compare comp); void sort(); template <typename Compare> void sort(Compare comp); void reverse()noexcept; // rearrange operations: void relocate(iterator position,iterator i); void relocate(iterator position,iterator first,iterator last); template<typename InputIterator> void rearrange(InputIterator first); } // 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 random access indices, we adopt the scheme outlined in the complexity signature section. The complexity signature of random access indices is:
c(n)=n*log(n),i(n)=1 (amortized constant),h(n)=1 (amortized constant),d(n)=m, where m is the distance
from the deleted element to the end of the sequence,r(n)=1 (constant),m(n)=1 (constant).shl(a,b)=a+bif a is nonzero,0otherwise.
rel(a,b,c)= ifa<b,c-a, elsea-b,
(shl and rel stand for shift left and
relocate, respectively.)
Random access indices are instantiated internally to multi_index_container
and specified by means of
indexed_by with the random_access
index specifier. 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).TagList must be an instantiation of
tag.
iterator
const_iterator
These types depend only onnode_typeand the position of the index in themulti_index_container.
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;aandbare themulti_index_containerobjects to which*thisandxbelong, respectively.
Returns:*this.
index class name& operator=(std::initializer_list<value_type> list);
Effects:wherea=list;ais themulti_index_containerobject to which*thisbelongs.
Returns:*this.
template <class InputIterator>
void assign(InputIterator first,InputIterator last);
Effects:clear(); insert(end(),first,last);
void assign(std::initializer_list<value_type> list);
Effects:assign(list.begin(),list.end());
void assign(size_type n,const value_type& value);
Effects:clear(); for(size_type i=0;i<n;++n)push_back(v);
iterator iterator_to(const value_type& x);
const_iterator iterator_to(const value_type& x)const;
Requires:xis a reference to an element of the container.
Returns: An iterator tox.
Complexity: Constant.
Exception safety:nothrow.
size_type capacity()const noexcept;
Returns: The total number of elementscsuch that, whensize()<c, back insertions happen in constant time (the general case as described byi(n)is amortized constant time.)
Note: Validity of iterators and references to elements is preserved in all insertions, regardless of the capacity status.
void reserve(size_type m);
Effects: If the previous value ofcapacity()was greater than or equal tom, nothing is done; otherwise, the internal capacity is changed so thatcapacity()>=m.
Complexity: If the capacity is not changed, constant; otherwiseO(n).
Exception safety: If the capacity is not changed,nothrow; otherwise, strong.
void shrink_to_fit();
Effects: Reducescapacity()tosize().
Complexity: If the capacity is not changed, constant; otherwiseO(n).
Exception safety: If the capacity is not changed,nothrow; otherwise, strong.
void resize(size_type n);
void resize(size_type n,const value_type& x);
Requires (first version):value_typeisDefaultInsertableintomulti_index_container.
Requires (second version):value_typeisCopyInsertableintomulti_index_container.
Effects: Ifsize()<n, tries to appendn-size()default-inserted elements (first version) or copies ofx(second version) at the end of the index. Ifn<size(), erases the lastsize()-nelements.
Note: If an expansion is requested, the size of the index is not guaranteed to benafter this operation (other indices may ban insertions.)
template<typename... Args>
std::pair<iterator,bool> emplace_front(Args&&... args);
Effects:Returns: The return value is a pairemplace(begin(),std::forward<Args>(args)...);p.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
std::pair<iterator,bool> push_front(const value_type& x);std::pair<iterator,bool> push_front(value_type&& x);
Effects:Returns: The return value is a pairinsert(begin(),x); // lvalue ref version insert(begin(),std::move(x)); // rvalue ref versionp.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
template<typename... Args>
std::pair<iterator,bool> emplace_back(Args&&... args);
Effects:Returns: The return value is a pairemplace(end(),std::forward<Args>(args)...);p.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
std::pair<iterator,bool> push_back(const value_type& x);std::pair<iterator,bool> push_back(value_type&& x);
Effects:Returns: The return value is a pairinsert(end(),x); // lvalue ref version insert(end(),std::move(x)); // rvalue ref versionp.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
template<typename... Args>
std::pair<iterator,bool> emplace(iterator position,Args&&... args);
Requires:value_typeisEmplaceConstructibleintomulti_index_containerfromargs.
Effects: Inserts avalue_typeobject constructed withstd::forward<Args>(args)...beforepositionif insertion is allowed by all other indices of themulti_index_container.
Returns: The return value is a pairp.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints 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(shl(end()-position,1) + I(n)).
Exception safety: Strong.
std::pair<iterator,bool> insert(iterator position,const value_type& x);std::pair<iterator,bool> insert(iterator position,value_type&& x);
Requires (first version):value_typeisCopyInsertableintomulti_index_container.positionis a valid iterator of the index.
Requires (second version):value_typeisMoveInsertableintomulti_index_container.positionis a valid iterator of the index.
Effects: Insertsxbeforepositionif insertion is allowed by all other indices of themulti_index_container.
Returns: The return value is a pairp.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints 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(shl(end()-position,1) + I(n)).
Exception safety: Strong.
void insert(iterator position,size_type m,const value_type& x);
Requires:positionis a valid iterator of the index.
Effects:Complexity:for(size_type i=0;i<m;++i)insert(position,x);O(shl(end()-position,m) + m*I(n+m)).
template<typename InputIterator>
void insert(iterator position,InputIterator first,InputIterator last);
Requires:positionis a valid iterator of the index.InputIteratoris an input iterator.value_typeisEmplaceConstructibleintomulti_index_containerfrom*first.firstandlastare not iterators into any index of themulti_index_containerto which this index belongs.lastis reachable fromfirst.
Effects: For each element of [first,last), in this order, inserts it beforepositionif insertion is allowed by all other indices of themulti_index_container.
Complexity:O(shl(end()-position,m) + m*I(n+m)), wheremis the number of elements in [first,last).
Exception safety: Basic.
void insert(iterator position,std::initializer_list<value_type> list);
Effects:insert(position,list.begin(),list.end());
insert_return_type insert(const_iterator position,node_type&& nh);
Requires:nh.empty() || get_allocator()==nh.get_allocator().
Effects: Does nothing ifnhis empty; otherwise, inserts the node owned bynhbeforepositionif insertion is allowed by all other indices of themulti_index_container.
Postconditions:nhis empty.
Returns: A valuepof typeinsert_return_type. Ifnhis empty,p.positionisend(),p.insertedisfalseandp.nodeis empty; on successful insertion,p.positionpoints to the element inserted,p.insertedistrueandp.nodeis empty; if the insertion failed,p.positionpoints to an element that caused the insertion to be banned,p.insertedisfalseandp.nodeowns the original node. Note that more than one element can be causing insertion not to be allowed.
Complexity:O(shl(end()-position,1) + I(n)).
Exception safety: Strong. If an exception is thrown,nhis not changed.
node_type extract(const_iterator position);
Requires:positionis 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.
iterator erase(iterator position);
Requires:positionis 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.
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(m*D(n)), wheremis 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_typeisCopyAssignable.positionis a valid dereferenceable iterator of the index.
Requires (second version):value_typeisMoveAssignable.positionis a valid dereferenceable iterator of the index.
Effects: Assigns the valuexto the element pointed to bypositioninto themulti_index_containerto which the index belongs if replacing is allowed by all other indices of themulti_index_container.
Postconditions: Validity ofpositionis preserved in all cases.
Returns:trueif the replacement took place,falseotherwise.
Complexity:O(R(n)).
Exception safety: Strong. If an exception is thrown by some user-provided operation themulti_index_containerto which the index belongs remains in its original state.
template<typename Modifier> bool modify(iterator position,Modifier mod);
Requires:modis a unary function object accepting arguments of typevalue_type&.positionis a valid dereferenceable iterator of the index. The execution ofmod(e), whereeis the element pointed to byposition, does not invoke any operation of themulti_index_containeraftereis directly modified or, before modification, if the operation would invalidateposition.
Effects: Callsmod(e)whereeis the element pointed to bypositionand rearranges*positioninto all the indices of themulti_index_container. Rearrangement on sequenced indices does not change the position of the element with respect to the index; rearrangement on other indices may or might not succeed. If the rearrangement fails, the element is erased.
Postconditions: Validity ofpositionis preserved if the operation succeeds.
Returns:trueif the operation succeeded,falseotherwise.
Complexity:O(M(n)).
Exception safety: Basic. If an exception is thrown by some user-provided operation (includingmod), then the element pointed to bypositionis erased.
template<typename Modifier,typename Rollback>
bool modify(iterator position,Modifier mod,Rollback back);
Requires:modandbackare unary function objects accepting arguments of typevalue_type&.positionis a valid dereferenceable iterator of the index. The execution ofmod(e), whereeis the element pointed to byposition, does not invoke any operation of themulti_index_containeraftereis directly modified or, before modification, if the operation would invalidateposition.back(e)does not invoke any operation of themulti_index_container.
Effects: Callsmod(e)whereeis the element pointed to bypositionand tries to rearrange*positioninto all the indices of themulti_index_container. Rearrangement on sequenced indices does not change the position of the element with respect to the index; rearrangement on other indices may or might not succeed. If the rearrangement fails,back(e)is invoked: if the resulting value ofeis consistent with its original position and constraints in all indices, the element is kept, otherwise it is erased.
Postconditions: Validity ofpositionis preserved except if the element is erased under the conditions described below.
Returns:trueif the operation succeeded,falseotherwise.
Complexity:O(M(n)).
Exception safety: Strong, except ifmodorbackthrow 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. Ifbackthrows inside the handling code executing after some other user-provided operation has thrown, it is the exception generated bybackthat is rethrown.
Random access indices replicate the interface of sequenced indices, which
in turn includes the list operations provided by std::list.
The syntax and behavior of these operations exactly matches those
of sequenced indices, but the associated complexity bounds differ in general.
template<typename Index> void splice(const_iterator position,Index&& x);
Requires:xis a non-const reference to an index of a node-compatiblemulti_index_container.positionis a valid iterator of the index, and must be exactlyend()if the source and destination containers are the same.
Effects:splice(position,x,x.begin(),x.end());
template<typename Index> std::pair<iterator,bool> splice(
const_iterator position,Index&& x,
typename std::remove_reference_t<Index>::const_iterator i);
Requires:xis a non-const reference to an index of a node-compatiblemulti_index_container. Ifget_allocator()!=x.get_allocator(),value_typemust beCopyInsertableinto the destinationmulti_index_container.positionis a valid iterator of the index.iis a valid dereferenceable iterator ofx.
Effects:Postconditions: If transfer succeeds, for any index in the source container having the same
- (Same container) if the source and destination containers are the same, repositions the element pointed to by
ibeforepositionunless both iterators refer to the same element.- (Transfer splice) else, if
get_allocator()==x.get_allocator(), transfers the node of the element referred to byiinto the destinationmulti_index_containerright beforepositionif insertion is allowed by all other indices of themulti_index_container.- (Destructive splice) else, insertion of
*iis tried beforeposition; if the operation is successful, the element is erased fromx.iterator/const_iteratortypes as the corresponding index in the destination container, iterators referring to*iremain valid and behave as iterators of the destination index.
Returns: The return value is a pairp.p.secondistrueif and only if insertion (either through transfer or copy insertion) took place or the source and destination containers are the same. Ifp.secondistrue,p.firstpoints to the inserted element or to*iif the source and destination containers are the same; otherwise,p.firstpoints 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: If the source and destination containers are the same,O(rel(position,i',i'+1)), wherei'is the projection ofiinto the index ofposition; otherwise,O(shl(end()-position,1) + I(n) + D(x.size())).
Exception safety: If the source and destination containers are the same,nothrow; otherwise strong.
Implementation note: The destructive variant of this operation is provided for reasons of backwards compatibility with previous versions of this library where allocator equality was not required.
template<typename Index> void splice(
const_iterator position,Index&& x,
typename std::remove_reference_t<Index>::const_iterator first,
typename std::remove_reference_t<Index>::const_iterator last);
Requires:xis a non-const reference to an index of a node-compatiblemulti_index_container. Ifget_allocator()!=x.get_allocator(),value_typemust beCopyInsertableinto the destinationmulti_index_container.positionis a valid iterator of the index and does not point to any element in [first,last). [first,last) is a valid range ofx.
Effects:Postconditions: For any index in the source container having the same
- (Same container) if the source and destination containers are the same, repositions all the elements of [
first,last), in this order, beforeposition.- (Transfer splice) else, if
get_allocator()==x.get_allocator(), then, for each node in [first,last), in this order, the node is transferred to themulti_index_containerright beforepositionif insertion is allowed by all other indices of themulti_index_container.- (Destructive splice) else, for each element in [
first,last), in this order, insertion is tried beforeposition; if the operation is successful, the element is erased fromx.iterator/const_iteratortypes as the corresponding index in the destination container, iterators referring to the transferred elements remain valid and behave as iterators of the destination index.
Complexity: If&x==this,O(rel(position,first,last)); else, if the source and destination containers are the same,O(n); otherwise,O(shl(end()-position,m) + m*(I(n+m) + D(x.size()))), wheremis the number of elements in [first,last).
Exception safety: If the source and destination containers are the same,nothrow; otherwise basic.
Implementation note: The destructive variant of this operation is provided for reasons of backwards compatibility with previous versions of this library where allocator equality was not required.
void remove(const value_type& value);
Effects: Erases all elements of the index which compare equal tovalue.
Complexity:O(n + m*D(n)), wheremis the number of elements erased.
Exception safety: Basic.
template<typename Predicate> void remove_if(Predicate pred);
Effects: Erases all elementsxof the index for whichpred(x)holds.
Complexity:O(n + m*D(n)), wheremis the number of elements erased.
Exception safety: Basic.
void unique();
Effects: Eliminates all but the first element from every consecutive group of equal elements referred to by the iteratoriin the range [first+1,last) for which*i==*(i-1).
Complexity:O(n + m*D(n)), wheremis the number of elements erased.
Exception safety: Basic.
template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
Effects: Eliminates all but the first element from every consecutive group of elements referred to by the iteratoriin the range [first+1,last) for whichbinary_pred(*i,*(i-1))holds.
Complexity:O(n + m*D(n)), wheremis the number of elements erased.
Exception safety: Basic.
void merge(index class name& x);
Requires: Eitherget_allocator()==x.get_allocator()orvalue_typeisCopyInsertableinto themulti_index_container.std::less<value_type>induces a strict weak ordering overvalue_type. Both the index andxare sorted according tostd::less<value_type>.
Effects: Attempts to splice every element ofxinto the corresponding position of the index (according to the order). The resulting sequence is stable, i.e. equivalent elements of either container preserve their relative position. In the special case&x==this, no operation is performed.
Postconditions: Elements in the index and remaining elements inxare sorted. Validity of iterators and references is preserved, except to elements removed fromxifget_allocator()!=x.get_allocator().
Complexity: If&x==this, constant; otherwiseO(n + x.size()*I(n+x.size()) + x.size()*D(x.size())).
Exception safety: If&x==this,nothrow; otherwise, basic.
template <typename Compare> void merge(index class name& x,Compare comp);
Requires: Eitherget_allocator()==x.get_allocator()orvalue_typeisCopyInsertableinto themulti_index_container.Compareinduces a strict weak ordering overvalue_type. Both the index andxare sorted according tocomp.
Effects: Attempts to splice every element ofxinto the corresponding position of the index (according tocomp). The resulting sequence is stable, i.e. equivalent elements of either container preserve their relative position. In the special case&x==this, no operation is performed.
Postconditions: Elements in the index and remaining elements inxare sorted according tocomp. Validity of iterators and references is preserved, except to elements removed fromxifget_allocator()!=x.get_allocator().
Complexity: If&x==this, constant; otherwiseO(n + x.size()*I(n+x.size()) + x.size()*D(x.size())).
Exception safety: If&x==this,nothrow; otherwise, basic.
void sort();
Requires:std::less<value_type>induces a strict weark ordering overvalue_type.
Effects: Sorts the index according tostd::less<value_type>. The sorting is stable, i.e. equivalent elements preserve their relative position.
Postconditions: Validity of iterators and references is preserved.
Complexity:O(n*log(n)).
Exception safety: Basic.
template <typename Compare> void sort(Compare comp);
Requires:Compareinduces a strict weak ordering overvalue_type.
Effects: Sorts the index according tocomp. The sorting is stable, i.e. equivalent elements preserve their relative position.
Postconditions: Validity of iterators and references is preserved.
Complexity:O(n*log(n)).
Exception safety: Basic.
void reverse()noexcept;
Effects: Reverses the order of the elements in the index.
Postconditions: Validity of iterators and references is preserved.
Complexity:O(n).
These operations, without counterpart in STL sequence containers
(although std::list::splice provides partially overlapping
functionality), perform individual and global repositioning of elements
inside the index.
void relocate(iterator position,iterator i);
Requires:positionis a valid iterator of the index.iis a valid dereferenceable iterator of the index.
Effects: Inserts the element pointed to byibeforeposition. Ifposition==i, no operation is performed.
Postconditions: No iterator or reference is invalidated.
Complexity:O(rel(position,i,i+1)).
Exception safety:nothrow.
void relocate(iterator position,iterator first,iterator last);
Requires:positionis a valid iterator of the index.firstandlastare valid iterators of the index.lastis reachable fromfirst.positionis not in the range [first,last).
Effects: The range of elements [first,last) is repositioned just beforeposition.
Postconditions: No iterator or reference is invalidated.
Complexity:O(rel(position,first,last)).
Exception safety:nothrow.
template<typename InputIterator> void rearrange(InputIterator first);
Requires: The range [first,std::advance(first,n)), wherenis the size of the index, is a free view of the index.
Effects: The elements are rearranged so as to match the order of the previously described view.
Postconditions: No iterator or reference is invalidated.
Complexity:O(n).
Exception safety: Basic.
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 random access 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: No additional requirements to those imposed by the container.Operation: saving of an
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()), whereiis the position of the random access index in the container.
iterator or const_iterator
it to an output archive (XML archive) ar.
Requires:Operation: loading of anitis a valid iterator of the index. The associatedmulti_index_containerhas been previously saved.
iterator or const_iterator
it' from an input archive (XML archive) ar.
Postconditions: On successful loading, ifitwas dereferenceable then*it'is the restored copy of*it, otherwiseit'==end().
Note: It is allowed thatitbe aconst_iteratorand the restoredit'aniterator, or viceversa.
Revised August 30th 2021
© Copyright 2003-2021 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)