* operator follows an iterator to its container element.
*itr = e: put e in a container element.
v = *itr: get the container element.
& is not useful for iterators.
itr = &v;++ behave as for pointers.
++itr advances the iterator itr to the next element and
returns the newly advanced iterator.
itr++ advances itr to the next element and returns the
original itr value.
--.
== determines if two iterators reference the
same container element.
itr1 < itr2 determines if the container element
referenced by itr1 appears to the left of the container element
referenced by itr2.
.front()".
itr1 < itr2 only makes sense if both iterators refer to the same
container.
== and <.
*, member access ->, pre- and
post-fix ++, and equality and inequality.
*itr returns the value being referenced by the iterator
itr.
* because it can only appear on the
right-hand side of an assignment statement.
itr is an input iterator, than
i = *itr is correct because * is being used to read
itr
*itr = i* is being used to write
itr
-> is defined as it is for pointers.
itr->mbr is the same as (*itr).mbr.
std::istream support input iterators.
* and pre- and post-fix ++.
*itr returns the container element being referenced by itr.
* because it can only appear on the
left-hand side of an assignment statement.
itr is an output iterator, than
i = *itr* is being used to read
itr.
*itr = i is correct because * is being used to write
itr
std::ostream support output iterators.
*, member access
->, pre- and post-fix ++, and equality and inequality.
=.
*itr = *itr + 1; is correct for a forward iterator.
-- for moving the iterator
back to the previous container element.
[], and ordering operator <.
itr = itr + 5; is equivalent to
for (unsigned i = 0; i < 5; i++) ++itr;
+= is also supported.
e_cnt = end_itr - start_itr;
start,end) that
defines a sequence of container elements.
(start, end) is only sensible when
start and end refers to elements within the same container.
start appears before end start < end.
C defines its own iterator types C::iterator and C::const_iterator.
std::vector<int> ivec; std::vector<int>::iterator itr; std::vector<int>::const_iterator citr;
C defines other iterator types too.
typedef std::vector<int> int_vec; typedef int_vec::iterator ivec_itr; typedef int_vec::const_iterator ivec_citr; int_vec ivec; ivec_itr itr; ivec_citr citr;
C has member functions that return iterators
referencing C's elements.
C.begin() returns an iterator to the first element in C.
C.begin() returns an iterator even if C has no elements.
std::vector<int> ivec; std::vector<int>::iterator start = ivec.begin();
C.end() returns an iterator to one-past the last element in C.
std::vector<int> ivec; std::vector<int>::iterator end = ivec.end();
C.begin() equals C.end() when C is empty.
This page last modified on 13 October 2003.