beautypg.com

Iterators, Standard c++ library iterators – HP Integrity NonStop J-Series User Manual

Page 126

background image

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Iterators

Tools.h++ provides several distinct methods for iterating over a collection class. Most collections
offer an apply member function, which applies your supplied function to every element of a
collection class before returning. Another form of iteration is provided by separate collaborating
iterator classes associated with many of the collections. For example, an

RWTPtrDlistIterator

can be used to visit each element of an

RWTPtrDlist

in turn. Iterators are described in

Chapter

10 (

Iterators in Collection Classes

)

.

Standard C++ Library Iterators

All Tools.h++ standard library-based collection class templates provide standard iterators. These
iterators are fully compliant with the Standard C++ Library requirements for iterators, making them
a powerful tool for using the classes in conjunction with the Standard C++ Library_especially the
algorithms. Although full treatment of iterators is beyond the scope of this guide, your Standard
C++ Library reference and tutorials will provide ample information.

The standard library-based collection class templates provide three types of iterators: forward,
bi-directional, and random-access. Forward iterators allow unidirectional traversal from beginning
to end. As suggested by the name, bidirectional iterators allow traversal in both directions--front to
back, and back to front. Random-access iterators are bidirectional as well, and further distinguished
by their ability to advance over an arbitrary number of elements in constant time. All of these
iterators allow access to the item at the current position via the dereference operator *.

Given iterator iter and an integral value n, the following basic operations are just some of those
supported:

Expression Meaning

Supported by:

++iter;

advance to next item and return

Forw, Bidir, Random

iter++;

advance to next item, return original value

Forw, Bidir, Random

*iter;

return reference to item at current position

Forw, Bidir, Random

--iter;

retreat to previous item and return

Bidir, Random

iter--;

retreat to previous item, return original value Bidir, Random

iter+=n;

advance n items and return

Random

iter-=n;

retreat n items and return

Random

This manual is related to the following products: