<iterator>advance
· back_insert_iterator
· back_inserter
· bidirectional_iterator_tag
· distance
· forward_iterator_tag
· front_insert_iterator
· front_inserter
· input_iterator_tag
· insert_iterator
· inserter
· istream_iterator
· istreambuf_iterator
· iterator
· iterator_traits
· operator!=
· operator==
· operator<
· operator<=
· operator>
· operator>=
· operator+
· operator-
· ostream_iterator
· ostreambuf_iterator
· output_iterator_tag
· random_access_iterator_tag
· reverse_iterator
namespace std {
struct input_iterator_tag;
struct output_iterator_tag;
struct forward_iterator_tag;
struct bidirectional_iterator_tag;
struct random_access_iterator_tag;
// TEMPLATE CLASSES
template<class C, class T, class Dist>
struct iterator;
template<class It>
struct iterator_traits;
template<class T>
struct iterator_traits<T *>
template<class RanIt>
class reverse_iterator;
template<class Cont>
class back_insert_iterator;
template<class Cont>
class front_insert_iterator;
template<class Cont>
class insert_iterator;
template<class U, class E, class T, class Dist>
class istream_iterator;
template<class U, class E, class T>
class ostream_iterator;
template<class E, class T>
class istreambuf_iterator;
template<class E, class T>
class ostreambuf_iterator;
// TEMPLATE FUNCTIONS
template<class RanIt>
bool operator==(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class U, class E, class T, class Dist>
bool operator==(
const istream_iterator<U, E, T, Dist>& lhs,
const istream_iterator<U, E, T, Dist>& rhs);
template<class E, class T>
bool operator==(
const istreambuf_iterator<E, T>& lhs,
const istreambuf_iterator<E, T>& rhs);
template<class RanIt>
bool operator!=(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class U, class E, class T, class Dist>
bool operator!=(
const istream_iterator<U, E, T, Dist>& lhs,
const istream_iterator<U, E, T, Dist>& rhs);
template<class E, class T>
bool operator!=(
const istreambuf_iterator<E, T>& lhs,
const istreambuf_iterator<E, T>& rhs);
template<class RanIt>
bool operator<(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class RanIt>
bool operator>(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class RanIt>
bool operator<=(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class RanIt>
bool operator>=(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class RanIt>
Dist operator-(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class RanIt>
reverse_iterator<RanIt> operator+(
Dist n,
const reverse_iterator<RanIt>& rhs);
template<class Cont>
back_insert_iterator<Cont> back_inserter(Cont& x);
template<class Cont>
front_insert_iterator<Cont> front_inserter(Cont& x);
template<class Cont, class Iter>
insert_iterator<Cont> inserter(Cont& x, Iter it);
template<class InIt, class Dist>
void advance(InIt& it, Dist n);
template<class Init, class Dist>
iterator_traits<InIt>::difference_type
distance(InIt first, InIt last);
};
Include the STL
standard header <iterator> to define a
number of classes, template classes, and template functions that
aid in the declaration and manipulation of iterators.
advancetemplate<class InIt, class Dist>
void advance(InIt& it, Dist n);
The template function effectively advances it by
incrementing it n times. If InIt is a
random-access iterator type, the function evaluates the
expression it += n. Otherwise, it performs each
increment by evaluating ++it. If InIt
is an input or forward iterator type, n must not be
negative.
back_insert_iteratortemplate<class Cont>
class back_insert_iterator
: public iterator<output_iterator_tag,
void, void, void, void> {
public:
typedef Cont container_type;
typedef typename Cont::reference reference;
typedef typename Cont::value_type value_type;
explicit back_insert_iterator(Cont& x);
back_insert_iterator&
operator=(const reference val);
back_insert_iterator& operator*();
back_insert_iterator& operator++();
back_insert_iterator operator++(int);
protected:
Cont *container;
};
The template class describes an output iterator object. It
inserts elements into a container of type Cont,
which it accesses via the protected pointer object it stores
called container.
The container must define:
reference, which is
the type of a reference to an element of the sequence
controlled by the containervalue_type, which is
the type of an element of the sequence controlled by the
containerpush_back(value_type c),
which appends a new element with value c to
the end of the sequenceback_insert_iterator::back_insert_iteratorexplicit back_insert_iterator(Cont& x);
The constructor initializes container
with &x.
back_insert_iterator::container_typetypedef Cont container_type;
The type is a synonym for the template parameter Cont.
back_insert_iterator::operator*back_insert_iterator& operator*();
The member function returns *this.
back_insert_iterator::operator++back_insert_iterator& operator++(); back_insert_iterator operator++(int);
The member functions both return *this.
back_insert_iterator::operator=back_insert_iterator&
operator=(const reference val);
The member function evaluates container.
push_back(val), then returns *this.
back_insert_iterator::referencetypedef typename Cont::reference reference;
The type describes a reference to an element of the sequence controlled by the associated container.
back_insert_iterator::value_typetypedef typename Cont::value_type value_type;
The type describes the elements of the sequence controlled by the associated container.
back_insertertemplate<class Cont>
back_insert_iterator<Cont> back_inserter(Cont& x);
The template member function returns back_insert_iterator<Cont>(x).
bidirectional_iterator_tagstruct bidirectional_iterator_tag
: public forward_iterator_tag {
};
The type is the same as iterator<It>::iterator_category
when It describes an object that can serve as a
bidirectional iterator.
distancetemplate<class Init, class Dist>
typename iterator_traits<InIt>::difference_type
distance(InIt first, InIt last);
The template function sets a count n to zero. It
then effectively advances first and increments n
until first == last. If InIt is a
random-access iterator type, the function evaluates the
expression n += last - first. Otherwise, it performs
each iterator increment by evaluating ++first.
forward_iterator_tagstruct forward_iterator_tag
: public input_iterator_tag {
};
The type is the same as iterator<It>::iterator_category
when It describes an object that can serve as a
forward iterator.
front_insert_iteratortemplate<class Cont>
class front_insert_iterator
: public iterator<output_iterator_tag,
void, void, void, void> {
public:
typedef Cont container_type;
typedef typename Cont::reference reference;
typedef typename Cont::value_type value_type;
explicit front_insert_iterator(Cont& x);
front_insert_iterator&
operator=(const reference val);
front_insert_iterator& operator*();
front_insert_iterator& operator++();
front_insert_iterator operator++(int);
protected:
Cont *container;
};
The template class describes an output iterator object. It
inserts elements into a container of type Cont,
which it accesses via the protected pointer object it stores
called container.
The container must define:
reference, which is
the type of a reference to an element of the sequence
controlled by the containervalue_type, which is
the type of an element of the sequence controlled by the
containerpush_front(value_type c),
which prepends a new element with value c to
the beginning of the sequencefront_insert_iterator::container_typetypedef Cont container_type;
The type is a synonym for the template parameter Cont.
front_insert_iterator::front_insert_iteratorexplicit front_insert_iterator(Cont& x);
The constructor initializes container
with &x.
front_insert_iterator::operator*front_insert_iterator& operator*();
The member function returns *this.
front_insert_iterator::operator++front_insert_iterator& operator++(); front_insert_iterator operator++(int);
The member functions both return *this.
front_insert_iterator::operator=front_insert_iterator&
operator=(const reference val);
The member function evaluates container.
push_front(val), then returns *this.
front_insert_iterator::referencetypedef typename Cont::reference reference;
The type describes a reference to an element of the sequence controlled by the associated container.
front_insert_iterator::value_typetypedef typename Cont::value_type value_type;
The type describes the elements of the sequence controlled by the associated container.
front_insertertemplate<class Cont>
front_insert_iterator<Cont> front_inserter(Cont& x);
The template member function returns front_insert_iterator<Cont>(x).
input_iterator_tagstruct input_iterator_tag {
};
The type is the same as iterator<It>::iterator_category
when It describes an object that can serve as an
input iterator.
insert_iteratortemplate<class Cont>
class insert_iterator
: public iterator<output_iterator_tag,
void, void, void, void> {
public:
typedef Cont container_type;
typedef typename Cont::reference reference;
typedef typename Cont::value_type value_type;
explicit insert_iterator(Cont& x,
typename Cont::iterator it);
insert_iterator&
operator=(const reference val);
insert_iterator& operator*();
insert_iterator& operator++();
insert_iterator& operator++(int);
protected:
Cont *container;
typename Cont::iterator iter;
};
The template class describes an output iterator object. It
inserts elements into a container of type Cont,
which it accesses via the protected pointer object it stores
called container.
It also stores the protected iterator object, of class Cont::iterator,
called iter.
The container must define:
iterator, which is
the type of an iterator for the containerreference, which is
the type of a reference to an element of the sequence
controlled by the containervalue_type, which is
the type of an element of the sequence controlled by the
containerinsert(iterator it,
value_type c), which inserts a new element with
value c immediately before the element
designated by it in the controlled sequence,
then returns an iterator that designates the inserted
elementinsert_iterator::container_typetypedef Cont container_type;
The type is a synonym for the template parameter Cont.
insert_iterator::insert_iteratorexplicit insert_iterator(Cont& x,
typename Cont::iterator it);
The constructor initializes container
with &x, and iter
with it.
insert_iterator::operator*insert_iterator& operator*();
The member function returns *this.
insert_iterator::operator++insert_iterator& operator++(); insert_iterator& operator++(int);
The member functions both return *this.
insert_iterator::operator=insert_iterator&
operator=(const reference val);
The member function evaluates iter = container.
insert(iter, val), then returns *this.
insert_iterator::referencetypedef typename Cont::reference reference;
The type describes a reference to an element of the sequence controlled by the associated container.
insert_iterator::value_typetypedef typename Cont::value_type value_type;
The type describes the elements of the sequence controlled by the associated container.
insertertemplate<class Cont, class Iter>
insert_iterator<Cont> inserter(Cont& x, Iter it);
The template member function returns insert_iterator<Cont>(x,
it).
istream_iteratortemplate<class U, class E,
class T = char_traits>
class Dist = ptrdiff_t>
class istream_iterator
: public iterator<input_iterator_tag,
U, Dist, U *, U&> {
public:
typedef E char_type;
typedef T traits_type;
typedef basic_istream<E, T> istream_type;
istream_iterator();
istream_iterator(istream_type& is);
const U& operator*() const;
const U *operator->() const;
istream_iterator<U, E, T, Dist>& operator++();
istream_iterator<U, E, T, Dist> operator++(int);
};
The template class describes an input iterator object. It
extracts objects of class U from an input
stream, which it accesses via an object it stores, of type
pointer to basic_istream<E, T>.
After constructing or incrementing an object of class istream_iterator
with a non-null stored pointer, the object attempts to extract
and store an object of type U from the associated
input stream. If the extraction fails, the object effectively
replaces the stored pointer with a null pointer (thus making an
end-of-sequence indicator).
istream_iterator::char_typetypedef E char_type;
The type is a synonym for the template parameter E.
istream_iterator::istream_iteratoristream_iterator(); istream_iterator(istream_type& is);
The first constructor initializes the input stream pointer
with a null pointer. The second constructor initializes the input
stream pointer with &is, then attempts to
extract and store an object of type U.
istream_iterator::istream_typetypedef basic_istream<E, T> istream_type;
The type is a synonym for basic_istream<E, T>.
istream_iterator::operator*const U& operator*() const;
The operator returns the stored object of type U.
istream_iterator::operator->const U *operator->() const;
The operator returns &**this.
istream_iterator::operator++istream_iterator<U, E, T, Dist>& operator++(); istream_iterator<U, E, T, Dist> operator++(int);
The first operator attempts to extract and store an object of
type U from the associated input stream. The second
operator makes a copy of the object, increments the object, then
returns the copy.
istream_iterator::traits_typetypedef T traits_type;
The type is a synonym for the template parameter T.
istreambuf_iteratortemplate<class E, class T = char_traits<E> >
class istreambuf_iterator
: public iterator<input_iterator_tag,
E, typename T::off_type, E *, E&> {
public:
typedef E char_type;
typedef T traits_type;
typedef typename T::int_type int_type;
typedef basic_streambuf<E, T> streambuf_type;
typedef basic_istream<E, T> istream_type;
istreambuf_iterator(streambuf_type *sb = 0) throw();
istreambuf_iterator(istream_type& is) throw();
const E& operator*() const;
const E *operator->();
istreambuf_iterator& operator++();
istreambuf_iterator operator++(int);
bool equal(const istreambuf_iterator& rhs);
};
The template class describes an input iterator object. It
extracts elements of class E from an input
stream buffer, which it accesses via an object it stores, of
type pointer to basic_streambuf<E, T>.
After constructing or incrementing an object of class istreambuf_iterator
with a non-null stored pointer, the object effectively attempts
to extract and store an object of type E from the
associated itput stream. (The extraction may be delayed, however,
until the object is actually dereferenced or copied.) If the
extraction fails, the object effectively replaces the stored
pointer with a null pointer (thus making an end-of-sequence
indicator).
istreambuf_iterator::char_typetypedef E char_type;
The type is a synonym for the template parameter E.
istreambuf_iterator::equalbool equal(const istreambuf_iterator& rhs);
The member function returns true only if the stored
streambbuffer pointers for the object and rhs are
both null pointers or are both non-null pointers.
istreambuf_iterator::int_typetypedef typename T:int_type int_type;
The type is a synonym for T::int_type.
istreambuf_iterator::istream_typetypedef basic_istream<E, T> istream_type;
The type is a synonym for basic_istream<E, T>.
istreambuf_iterator::istreambuf_iteratoristreambuf_iterator(streambuf_type *sb = 0) throw(); istreambuf_iterator(istream_type& is) throw();
The first constructor initializes the input stream-buffer
pointer with sb. The second constructor initializes
the input stream-buffer pointer with is.rdbuf(),
then (eventually) attempts to extract and store an object of type
E.
istreambuf_iterator::operator*const E& operator*() const;
The operator returns the stored object of type E.
istreambuf_iterator::operator++istreambuf_iterator& operator++(); istreambuf_iterator operator++(int);
The first operator (eventually) attempts to extract and store
an object of type E from the associated input
stream. The second operator makes a copy of the object,
increments the object, then returns the copy.
istreambuf_iterator::operator->const E *operator->() const;
The operator returns &**this.
istreambuf_iterator::streambuf_typetypedef basic_streambuf<E, T> streambuf_type;
The type is a synonym for basic_streambuf<E, T>.
istreambuf_iterator::traits_typetypedef T traits_type;
The type is a synonym for the template parameter T.
iteratortemplate<class C, class T, class Dist = ptrdiff_t
class Pt, class Rt>
struct iterator {
typedef C iterator_category;
typedef T value_type;
typedef Dist difference_type;
typedef Pt pointer;
typedef Rt reference;
};
The template class serves as a base type for all iterators. It
defines the member types iterator_category
(a synonym for the template parameter C), value_type (a synonym for
the template parameter T), difference_type (a
synonym for the template parameter Dist), pointer (a synonym for the
template parameter Pt), and reference (a synonym for
the template parameter T).
iterator_traitstemplate<class It>
struct iterator_traits {
typedef typename It::iterator_category iterator_category;
typedef typename It::value_type value_type;
typedef typename It::difference_type difference_type;
typedef typename It::pointer pointer;
typedef typename It::reference reference;
};
template<class T>
struct iterator_traits<T *> {
typedef random_access_iterator_tag iterator_category;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef T *pointer;
typedef T& reference;
};
The template class determines several critical types
associated with the iterator type It. It defines the
member types iterator_category
(a synonym for It::iterator_category), value_type (a
synonym for It::value_type), difference_type
(a synonym for It::difference_type), pointer (a synonym for
It::pointer), and reference (a synonym
for It::reference).
The partial specialization determines the critical types
associated with an object pointer type T *. In this implementation,
you can also use several template functions that do not make use
of partial specialization:
template<class C, class T, class Dist>
C _Iter_cat(const iterator<C, T, Dist>&);
template<class T>
random_access_iterator_tag _Iter_cat(const T *);
template<class C, class T, class Dist>
T *_Val_type(const iterator<C, T, Dist>&);
template<class T>
T *_Val_type(const T *);
template<class C, class T, class Dist>
Dist *_Dist_type(const iterator<C, T, Dist>&);
template<class T>
ptrdiff_t *_Dist_type(const T *);
which determine several of the same types a bit more indirectly. You use these functions as arguments on a function call. Their sole purpose is to supply a useful template class parameter to the called function.
operator!=template<class RanIt>
bool operator!=(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class U, class E, class T, class Dist>
bool operator!=(
const istream_iterator<U, E, T, Dist>& lhs,
const istream_iterator<U, E, T, Dist>& rhs);
template<class E, class T>
bool operator!=(
const istreambuf_iterator<E, T>& lhs,
const istreambuf_iterator<E, T>& rhs);
The template operator returns !(lhs == rhs).
operator==template<class RanIt>
bool operator==(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
template<class U, class E, class T, class Dist>
bool operator==(
const istream_iterator<U, E, T, Dist>& lhs,
const istream_iterator<U, E, T, Dist>& rhs);
template<class E, class T>
bool operator==(
const istreambuf_iterator<E, T>& lhs,
const istreambuf_iterator<E, T>& rhs);
The first template operator returns true only if lhs.current ==
rhs.current. The second template operator returns true
only if both lhs and rhs store the same
stream pointer. The third template operator returns lhs.equal(rhs).
operator<template<class RanIt>
bool operator<(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
The template operator returns rhs.current
< lhs.current [sic].
operator<=template<class RanIt>
bool operator<=(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
The template operator returns !(rhs < lhs).
operator>template<class RanIt>
bool operator>(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
The template operator returns rhs < lhs.
operator>=template<class RanIt>
bool operator>=(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
The template operator returns !(lhs < rhs).
operator+template<class RanIt>
reverse_iterator<RanIt> operator+(Dist n,
const reverse_iterator<RanIt>& rhs);
The template operator returns rhs + n.
operator-template<class RanIt>
Dist operator-(
const reverse_iterator<RanIt>& lhs,
const reverse_iterator<RanIt>& rhs);
The template operator returns rhs.current -
lhs.current [sic].
ostream_iteratortemplate<class U, class E,
class T = char_traits> >
class ostream_iterator
: public iterator<output_iterator_tag,
void, void, void, void> {
public:
typedef U value_type;
typedef E char_type;
typedef T traits_type;
typedef basic_ostream<E, T> ostream_type;
ostream_iterator(ostream_type& os);
ostream_iterator(ostream_type& os, const E *delim);
ostream_iterator<U, E, T>& operator=(const U& val);
ostream_iterator<U, E, T>& operator*();
ostream_iterator<U, E, T>& operator++();
ostream_iterator<U, E, T> operator++(int);
};
The template class describes an output iterator object. It
inserts objects of class U into an output
stream, which it accesses via an object it stores, of type
pointer to basic_ostream<E, T>.
It also stores a pointer to a delimiter string, a
null-terminated string of elements of type E, which
is appended after each insertion. (Note that the string itself is
not copied by the constructor.
ostream_iterator::char_typetypedef E char_type;
The type is a synonym for the template parameter E.
ostream_iterator::operator*ostream_iterator<U, E, T>& operator*();
The operator returns *this.
ostream_iterator::operator++ostream_iterator<U, E, T>& operator++(); ostream_iterator<U, E, T> operator++(int);
The operators both return *this.
ostream_iterator::operator=ostream_iterator<U, E, T>& operator=(const U& val);
The operator inserts val into the output stream
associated with the object, then returns *this.
ostream_iterator::ostream_iteratorostream_iterator(ostream_type& os); ostream_iterator(ostream_type& os, const E *delim);
The first constructor initializes the output stream pointer
with &os. The delimiter string pointer
designates an empty string. The second constructor initializes
the output stream pointer with &os and the
delimiter string pointer with delim.
ostream_iterator::ostream_typetypedef basic_ostream<E, T> ostream_type;
The type is a synonym for basic_ostream<E, T>.
ostream_iterator::traits_typetypedef T traits_type;
The type is a synonym for the template parameter T.
ostream_iterator::value_typetypedef U value_type;
The type is a synonym for the template parameter U.
ostreambuf_iteratortemplate<class E, class T = char_traits<E> >
class ostreambuf_iterator
: public iterator<output_iterator_tag,
void, void, void, void> {
public:
typedef E char_type;
typedef T traits_type;
typedef basic_streambuf<E, T> streambuf_type;
typedef basic_ostream<E, T> ostream_type;
ostreambuf_iterator(streambuf_type *sb) throw();
ostreambuf_iterator(ostream_type& os) throw();
ostreambuf_iterator& operator=(E x);
ostreambuf_iterator& operator*();
ostreambuf_iterator& operator++();
T1 operator++(int);
bool failed() const throw();
};
The template class describes an output iterator object. It
inserts elements of class E into an output
stream buffer, which it accesses via an object it stores, of
type pointer to basic_streambuf<E, T>.
ostreambuf_iterator::char_typetypedef E char_type;
The type is a synonym for the template parameter E.
ostreambuf_iterator::failedbool failed() const throw();
The member function returns true only if no insertion into the output stream buffer has earlier failed.
ostreambuf_iterator::operator*ostreambuf_iterator& operator*();
The operator returns *this.
ostreambuf_iterator::operator++ostreambuf_iterator& operator++(); T1 operator++(int);
The first operator returns *this. The second
operator returns an object of some type T1 that can
be converted to ostreambuf_iterator<E, T>.
ostreambuf_iterator::operator=ostreambuf_iterator& operator=(E x);
The operator inserts x into the associated stream
buffer, then returns *this.
ostreambuf_iterator::ostream_typetypedef basic_ostream<E, T> ostream_type;
The type is a synonym for basic_ostream<E, T>.
ostreambuf_iterator::ostreambuf_iteratorostreambuf_iterator(streambuf_type *sb) throw(); ostreambuf_iterator(ostream_type& is) throw();
The first conttructor initializes the output stream-buffer
pointer with sb. The second constructor initializes
the output stream-buffer pointer with is.rdbuf().
(The stored pointer must not be a null pointer.)
ostreambuf_iterator::streambuf_typetypedef basic_streambuf<E, T> streambuf_type;
The type is a synonym for basic_streambuf<E, T>.
ostreambuf_iterator::traits_typetypedef T traits_type;
The type is a synonym for the template parameter T.
output_iterator_tagstruct output_iterator_tag {
};
The type is the same as iterator<It>::iterator_category
when It describes an object that can serve as a
output iterator.
random_access_iterator_tagstruct random_access_iterator_tag
: public bidirectional_iterator_tag {
};
The type is the same as iterator<It>::iterator_category
when It describes an object that can serve as a
random-access iterator.
reverse_iteratortemplate<class RanIt>
class reverse_iterator : public iterator<
typename iterator_traits<RanIt>::iterator_category,
typename iterator_traits<RanIt>::value_type,
typename iterator_traits<RanIt>::difference_type,
typename iterator_traits<RanIt>::pointer,
typename iterator_traits<RanIt>::reference> {
typedef typename iterator_traits<RanIt>::difference_type
Dist;
typedef typename iterator_traits<RanIt>::pointer
Ptr;
typedef typename iterator_traits<RanIt>::reference
Ref;
public:
typedef RanIt iter_type;
reverse_iterator();
explicit reverse_iterator(RanIt x);
RanIt base() const;
Ref operator*() const;
Ptr operator->() const;
reverse_iterator& operator++();
reverse_iterator operator++(int);
reverse_iterator& operator--();
reverse_iterator operator--();
reverse_iterator& operator+=(Dist n);
reverse_iterator operator+(Dist n) const;
reverse_iterator& operator-=(Dist n);
reverse_iterator operator-(Dist n) const;
Ref operator[](Dist n) const;
protected:
RanIt current;
};
The template class describes an object that behaves like a
random-access iterator, only in reverse. It stores a
random-access iterator of type RanIt in the
protected object current.
Incrementing the object x of type reverse_iterator
decrements x.current, and decrementing x
increments x.current. Moreover, the expression *x
evaluates to *(current - 1), of type Ref.
Typically, Ref is type T&.
Thus, you can use an object of class reverse_iterator
to access in reverse order a sequence that is traversed in order
by a random-access iterator.
Several STL containers
specialize reverse_iterator for RanIt a
bidirectional iterator. In these cases, you must not call any of
the member functions operator+=, operator+,
operator-=, operator-, or operator[].
reverse_iterator::baseRanIt base() const;
The member function returns current.
reverse_iterator::iter_typetypedef RanIt iter_type;
The type is a synonym for the template parameter RanIt.
reverse_iterator::operator*Ref operator*() const;
The operator returns *(current -
1).
reverse_iterator::operator+reverse_iterator operator+(Dist n) const;
The operator returns reverse_iterator(*this) += n.
reverse_iterator::operator++reverse_iterator& operator++(); reverse_iterator operator++(int);
The first (preincrement) operator evaluates --current.
then returns *this.
The second (postincrement) operator makes a copy of *this,
evaluates --current, then returns the copy.
reverse_iterator::operator+=reverse_iterator& operator+=(Dist n);
The operator evaluates current - n.
then returns *this.
reverse_iterator::operator-reverse_iterator operator-(Dist n) const;
The operator returns reverse_iterator(*this) -= n.
reverse_iterator::operator--reverse_iterator& operator--(); reverse_iterator operator--();
The first (predecrement) operator evaluates ++current.
then returns *this.
The second (postdecrement) operator makes a copy of *this,
evaluates ++current, then returns the copy.
reverse_iterator::operator-=reverse_iterator& operator-=(Dist n);
The operator evaluates current + n.
then returns *this.
reverse_iterator::operator->Ptr operator->() const;
The operator returns &**this.
reverse_iterator::operator[]Ref operator[](Dist n) const;
The operator returns *(*this + n).
reverse_iterator::pointer_typetypedef Ptr pointer_type;
The type is a synonym for the template parameter Ref.
reverse_iterator::reference_typetypedef Ref reference_type;
The type is a synonym for the template parameter Ref.
reverse_iterator::reverse_iteratorreverse_iterator(); explicit reverse_iterator(RanIt x);
The first constructor initializes current
with its default constructor. The second constructor initializes current
with current(x).
See also the Table of Contents .
Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.