Книга: Standard Template Library Programmer
Разделы на этой странице:
Component type: concept
A Trivial Iterator is an object that may be dereferenced to refer to some other object. Arithmetic operations (such as increment and comparison) are not guaranteed to be supported.
Assignable, Equality Comparable, Default Constructible
|Value type||The type of the value obtained by dereferencing a Trivial Iterator|
X A type that is a model of Trivial Iterator
T The value type of X
x, y Object of type X
t Object of type T
A type that is a model of Trivial Iterator may be mutable, meaning that the values referred to by objects of that type may be modified, or constant, meaning that they may not. For example, int* is a mutable iterator type and const int* is a constant iterator type. If an iterator type is mutable, this implies that its value type is a model of Assignable; the converse, though, is not necessarily true.
A Trivial Iterator may have a singular value, meaning that the results of most operations, including comparison for equality, are undefined. The only operation that a is guaranteed to be supported is assigning a nonsingular iterator to a singular iterator.
A Trivial Iterator may have a dereferenceable value, meaning that dereferencing it yields a well-defined value. Dereferenceable iterators are always nonsingular, but the converse is not true. For example, a null pointer is nonsingular (there are well defined operations involving null pointers) even thought it is not dereferenceable.
Invalidating a dereferenceable iterator means performing an operation after which the iterator might be nondereferenceable or singular. For example, if p is a pointer, then delete p invalidates p.
In addition to the expressions defined in Assignable, Equality Comparable, and Default Constructible, the following expressions must be valid.
|Name||Expression||Type requirements||Return type|
|Dereference||*x||Convertible to T |
||X is mutable|
||T is a type for which x.m is defined|
||x is singular|
||x is dereferenceable|
||x is dereferenceable||*x is a copy of t|
||x is dereferenceable||Equivalent to (*x).m|
The complexity of operations on trivial iterators is guaranteed to be amortized constant time.
|Identity||x == y if and only if &*x == &*y|
• A pointer to an object that is not part of an array.
 The requirement for the return type of *x is specified as "convertible to T", rather than simply T, because it sometimes makes sense for an iterator to return some sort of proxy object instead of the object that the iterator conceptually points to. Proxy objects are implementation details rather than part of an interface (one use of them, for example, is to allow an iterator to behave differently depending on whether its value is being read or written), so the value type of an iterator that returns a proxy is still T.
 Defining operator-> for iterators depends on a feature that is part of the C++ language but that is not yet implemented by all C++ compilers. If your compiler does not yet support this feature, the workaround is to use (*it).m instead of it->m.
Input Iterator, Output Iterator, Forward Iterator, Bidirectional Iterator, Random Access Iterator, Iterator Overview