ReversibleContainer |
Detailed Description
A Reversible Container is a ForwardContainer whose iterators are BidirectionalIterator. It allows backwards iteration through the container.
- Refinement Of:
- ForwardContainer
- Associated Types:
- Two new types are introduced. In addition, the iterator type and the const iterator type must satisfy a more stringent requirement than for a ForwardContainer. The iterator and reverse iterator types must be BidirectionalIterator, not merely ForwardIterator.
Reverse iterator type X::reverse_iterator
A ReverseIterator adaptor whose base iterator type is the container's iterator type. Incrementing an object of type reverse_iterator
moves backwards through the container: the ReverseIterator adaptor mapsoperator++
tooperator--
.Const reverse iterator type X::const_reverse_iterator
A ReverseIterator adaptor whose base iterator type is the container's const iterator type. [1]
- Notation:
X
A type that is a model of Reversible Container a
,b
Object of type X
- Definitions:
- Valid Expressions:
- In addition to the expressions defined in ForwardContainer, the following expressions must be valid.
Name Expression Type requirements Return type Beginning of range a.rbegin()
reverse_iterator
ifa
is mutable,const_reverse_iterator
otherwise [1]End of range a.rend()
reverse_iterator
ifa
is mutable,const_reverse_iterator
otherwise [1]
- Expression Semantics:
- Semantics of an expression is defined only where it is not defined in ForwardContainer, or where there is additional information.
Name Expression Precondition Semantics Postcondition Beginning of reverse range a.rbegin()
Equivalent to X::reverse_iterator(a.end())
.a.rbegin()
is dereferenceable or past-the-end. It is past-the-end if and only ifa.size() == 0
.End of reverse range a.rend()
Equivalent to X::reverse_iterator(a.begin())
.a.end()
is past-the-end.
- Complexity Guarantees:
- The run-time complexity of
rbegin()
andrend()
is amortized constant time.
- Invariants:
Valid range [a.rbegin(), a.rend())
is a valid range.Equivalence of ranges The distance from a.begin()
toa.end()
is the same as the distance froma.rbegin()
toa.rend()
.
- Type(s) Modeling this Concept:
- Vector
- List
- Deque
- Notes:
[1] A Container's iterator type and const iterator type may be the same type: a container need not provide mutable iterators. It follows from this that the reverse iterator type and the const reverse iterator type may also be the same.
- See Also:
- The Iterators, BidirectionalIterator, Sequence