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. Validity of iterators and references to elements
is preserved in all operations, regardless of the capacity status.

As is the case with sequenced indices, random access indices have the
following limitations with respect to STL sequence containers:

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 STL sequence containers.

Elements in a random access index are not mutable, and can only be changed
by means of replace and
modify member functions.

Having these restrictions into account, random access indices are models
of Random Access Container and
Back Insertion Sequence. Although these indices do
not model
Front Insertion Sequence, because front insertion
and deletion take linear time, front operations are nonetheless provided
to match the interface of sequenced indices.
We only describe those types and operations that are
either not present in the concepts modeled or do not exactly conform
to the requirements for these types of containers.

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:

Requires:InputIterator is a model of
Input Iterator over elements of type
value_type or a type convertible to value_type.
first and last are not iterators into any
index of the multi_index_container to which this index belongs.
last is reachable from first.
Effects:

Returns: The total number of elements c such that, when
size()<c, back insertions happen in constant time (the
general case as described by
i(n) is amortized
constant time.)Note: Validity of iterators and references to elements
is preserved in all insertions, regardless of the capacity status.

Effects: If the previous value of capacity()
was greater than or equal to m, nothing is done;
otherwise, the internal capacity is changed so that
capacity()>=m.Complexity: If the capacity is not changed, constant;
otherwise O(n).Exception safety: If the capacity is not changed, nothrow;
otherwise, strong.

Effects: Inserts x at the beginning of the sequence if
no other index of the multi_index_container bans the insertion.Returns: The return value is a pair p. p.second
is true 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(n+I(n)).Exception safety: Strong.

std::pair<iterator,bool> push_back(const value_type& x);

Effects: Inserts x at the end of the sequence if
no other index of the multi_index_container bans the insertion.Returns: The return value is a pair p. p.second
is true 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.

Requires:position is a valid iterator of the index.
Effects: Inserts x before position if insertion
is allowed by all other indices of the multi_index_container.Returns: The return value is a pair p. p.second
is true 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(shl(end()-position,1) + I(n)).Exception safety: Strong.

Requires:position is a valid iterator of the index.
InputIterator is a model of
Input Iterator over elements of type
value_type or a type convertible to value_type.
first and last are not iterators into any
index of the multi_index_container to which this index belongs.
last is reachable from first.
Effects:

while(first!=last)insert(position,*first++);

Complexity:O(shl(end()-position,m) + m*I(n+m)),
where m is the number of elements in
[first,last).Exception safety: Basic.

iterator erase(iterator position);

Requires:position is a valid dereferenceable iterator
of the index.
Effects: Deletes the element pointed to by position.Returns: An iterator pointing to the element immediately following
the one that was deleted, or end()
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)), where m is
the number of elements in [first,last).Exception safety:nothrow.

Requires:position is a valid dereferenceable iterator
of the index.
Effects: Assigns the value x to the element pointed
to by position into the multi_index_container to which
the index belongs if replacing is allowed by all other indices of the
multi_index_container.Postconditions: Validity of position is preserved
in all cases.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 the multi_index_container to which the index
belongs remains in its original state.

Requires:Modifier is a model of
Unary Function accepting arguments of type
value_type&. position is a valid dereferenceable
iterator of the index.
Effects: Calls mod(e) where e is the element
pointed to by position and rearranges *position into
all the indices of the multi_index_container. Rearrangement on
rancom access indices does not change the position of the element with respect
to the index; rearrangement on other indices may or might not suceed. If the
rearrangement fails, the element is erased.Postconditions: Validity of position is preserved if the
operation succeeds.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 (except possibly mod), then
the element pointed to by position is erased.

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.

void splice(iterator position,index class name& x);

Requires:position is a valid iterator of the index.
&x!=this.
Effects: Inserts the contents of x before position,
in the same order as they were in x. Those elements succesfully
inserted are erased from x.Complexity:O(shl(end()-position,x.size()) + x.size()*I(n+x.size()) + x.size()*D(x.size())).Exception safety: Basic.

void splice(iterator position,index class name& x,iterator i);

Requires:position is a valid iterator of the index.
i is a valid dereferenceable iterator x.Effects: Inserts the element pointed to by i before
position: if insertion is succesful, the element is erased from
x. In the special case &x==this, no copy or
deletion is performed, and the operation is always succesful. If
position==i, no operation is performed.Postconditions: If &x==this, no iterator or reference
is invalidated.Complexity: If &x==this, O(rel(position,i,i+1));
otherwise O(shl(end()-position,1) + I(n) + D(n)).Exception safety: If &x==this, nothrow;
otherwise, strong.

Requires:position is a valid iterator of the index.
first and last are valid iterators of x.
last is reachable from first. position
is not in the range [first,last).Effects: For each element in the range [first,last),
insertion is tried before position; if the operation is succesful,
the element is erased from x. In the special case
&x==this, no copy or deletion is performed, and insertions are
always succesful.Postconditions: If &x==this, no iterator or reference
is invalidated.Complexity: If &x==this,
O(rel(position,first,last)); otherwise
O(shl(end()-position,m) + m*I(n+m) + m*D(x.size()))
where m is the number of elements in [first,last).Exception safety: If &x==this, nothrow;
otherwise, basic.

void remove(const value_type& value);

Effects: Erases all elements of the index which compare equal to
value.Complexity:O(n + m*D(n)), where m
is the number of elements erased.Exception safety: Basic.

template<typename Predicate> void remove_if(Predicate pred);

Effects: Erases all elements x of the index for which
pred(x) holds.Complexity:O(n + m*D(n)), where m
is 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 iterator i in the range
[first+1,last) for which *i==*(i-1).Complexity:O(n + m*D(n)), where m
is the number of elements erased.Exception safety: Basic.

Effects: Eliminates all but the first element from every consecutive
group of elements referred to by the iterator i in the range
[first+1,last) for which
binary_pred(*i,*(i-1)) holds.Complexity:O(n + m*D(n)), where m
is the number of elements erased.Exception safety: Basic.

void merge(index class name& x);

Requires:std::less<value_type> is a
Strict Weak Ordering over value_type.
Both the index and x are sorted according to
std::less<value_type>.Effects: Attempts to insert every element of x into the
corresponding position of the index (according to the order). Elements
successfully inserted are erased from x. 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 in
x are sorted.
Validity of iterators to the index and of non-erased elements of x
references is preserved.Complexity: If &x==this, constant; otherwise
O(n + x.size()*I(n+x.size()) + x.size()*D(x.size())).Exception safety: If &x==this, nothrow;
otherwise, basic.

Requires:Compare is a
Strict Weak Ordering over value_type.
Both the index and x are sorted according to comp.Effects: Attempts to insert every element of x into the
corresponding position of the index (according to comp).
Elements successfully inserted are erased from x. 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 in
x are sorted according to comp.
Validity of iterators to the index and of non-erased elements of x
references is preserved.Complexity: If &x==this, constant; otherwise
O(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> is a
Strict Weak Ordering over value_type.Effects: Sorts the index according to
std::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:Compare is a
Strict Weak Ordering over value_type.Effects: Sorts the index according to comp. 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();

Effects: Reverses the order of the elements in the index.Postconditions: Validity of iterators and references is preserved.Complexity:O(n).Exception safety:nothrow.

Requires:position is a valid iterator of the index.
i is a valid dereferenceable iterator of the index.Effects: Inserts the element pointed to by i before
position. If position==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:position is a valid iterator of the index.
first and last are valid iterators of the index.
last is reachable from first. position
is not in the range [first,last).Effects: The range of elements [first,last)
is repositioned just before position.Postconditions: No iterator or reference is invalidated.Complexity:O(rel(position,first,last)).Exception safety:nothrow.

Requires: The range [first,
std::advance(first,n)),
where n is 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_containerserialization section.

Operation: saving of a multi_index_containerm to an
output archive (XML archive) ar.

Requires: No additional requirements to those imposed by the container.

Operation: loading of a multi_index_containerm' from an
input archive (XML archive) ar.

Requires: No additional requirements to those imposed by the container.Postconditions: On succesful 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()),
where i is the position of the random access index in the container.

Operation: saving of an iterator or const_iteratorit to an output archive (XML archive) ar.

Requires:it is a valid iterator of the index. The associated
multi_index_container has been previously saved.

Operation: loading of an iterator or const_iteratorit' from an input archive (XML archive) ar.

Postconditions: On succesful loading, if it was dereferenceable
then *it' is the restored copy of *it, otherwise
it'==end().Note: It is allowed that it be a const_iterator
and the restored it' an iterator, or viceversa.