X | A type that is a model of Range. |
a, b | Object of type X. |
T | The value type of X. |
Value type | X::value_type | The type of the object stored in a Range. |
Iterator type | X::iterator | The type of iterator used to iterate through a Range's elements. The iterator's value type is expected to be the Range's value type. A conversion from the iterator type to the const iterator type must exist. The iterator type must at least be an InputIterator. |
Const iterator type | X::const_iterator | A type of iterator that may be used to examine, but not to modify, a Range's elements. |
Reference type | X::reference | A type that behaves like a reference to the Range's value type. [1] |
Distance type | X::difference_type | A signed integral type used to represent the distance between two of the Range's iterators. This type must be the same as the iterator's distance type. |
Size type | X::size_type | An unsigned integral type that can represent any nonnegative value of the Range's distance type. |
Name | Expression | Return type |
---|---|---|
Beginning of range | a.begin() | iterator if a is mutable, const_iterator otherwise |
End of range | a.end() | iterator if a is mutable, const_iterator otherwise |
Size | a.size() | size_type | Empty range | a.empty() | Convertible to bool |
Name | Expression | Semantics | Postcondition |
---|---|---|---|
Beginning of range | a.begin() | Returns an iterator pointing to the first element in the Range. | a.begin() is either dereferenceable or past-the-end. It is past-the-end if and only if a.size() == 0. |
End of range | a.end() | Returns an iterator pointing one past the last element in the Range. | a.end() is past-the-end. |
Size | a.size() | Returns the size of the Collection, that is, its number of elements. | a.size() >= 0 |
Empty Collection | a.empty() | Equivalent to a.size() == 0. (But possibly faster.) | |
Valid range | For any Range a, [a.begin(), a.end()) is a valid range. |
Range size | a.size() is equal to the distance from a.begin() to a.end(). |
Completeness | An algorithm that iterates through the range [a.begin(), a.end()) will pass through every element of a. |
Reverse Iterator type | X::reverse_iterator | The type of iterator used to iterate through a Range's elements in reverse order. The iterator's value type is expected to be the Range's value type. A conversion from the reverse iterator type to the const reverse iterator type must exist. The iterator type must at least be a BidirectionalIterator. |
Const reverse iterator type | X::const_reverse_iterator | A type of reverse iterator that may be used to examine, but not to modify, a Range's elements. |
Name | Expression | Return type | Semantics |
---|---|---|---|
Beginning of range | a.rbegin() | reverse_iterator if a is mutable, const_reverse_iterator otherwise. | Equivalent to X::reverse_iterator(a.end()). |
End of range | a.rend() | reverse_iterator if a is mutable, const_reverse_iterator otherwise. | Equivalent to X::reverse_iterator(a.begin()). |
[1]
The reference type does not have to be a real C++ reference. The
requirements of the reference type depend on the context within which
the Range is being used. Specifically it depends on the
requirements the context places on the value type of the Range.
The reference type of the Range must meet the same requirements
as the value type. In addition, the reference objects must be
equivalent to the value type objects in the Range (which is
trivially true if they are the same). Also, in a mutable Range,
an assignment to the reference object must result in an assignment to
the object in the Range (again, which is trivially true if they
are the same object, but non-trivial if the reference type is a proxy
class).
Copyright © 2000 | Jeremy Siek, Univ.of Notre Dame and C++ Library & Compiler Group/SGI (jsiek@engr.sgi.com) |
Copyright © 2004 | Thorsten Ottosen. |