Iterators

Collaboration diagram for Iterators:

Iterators are used to access members of container classes. More...


Modules

 Insert Iterators
 Insert iterators are a special type of iterator that can insert elements into a container.

Classes

class  OLArrayIterator
 An iterator that can traverse arrays of objects. More...
class  OLAssociativeIterator
 An iterator for traversing associative containers like sets and maps. More...
class  OLBidirectionalIterator
 An iterator that can traverse a collection both forwards and backwards. More...
class  OLBitIterator
 An iterator that can traverse an array of bits. More...
class  OLDequeIterator
 An iterator that knows about double-ended queues. More...
class  OLForwardIterator
 An iterator that can go forward one step at a time. More...
class  OLHashIterator
 An iterator that knows about hash tables. More...
class  OLIterator
 An abstract base class for iterators. More...
class  OLListIterator
 An iterator for traversing linked lists. More...
class  OLRandomAccessIterator
 An iterator that provides random access. More...
class  OLReverseBidiIterator
 A class to reverse the behavior of a given iterator. More...
class  OLReverseRandomIterator
 A class to reverse the behavior of a given iterator. More...

Detailed Description

Iterators are used to access members of container classes.

There are various types of iterators that provide functionality that can vary depending on the type of container to which the iterator refers. Iterator types differ in the type of movement between elements that is allowed. All iterators provide the ability to access the element to which the iterator points and to assign a new value to the element. Additionally, they may provide forward stepwise motion, backward stepwise motion or arbitrary motion in either direction.

One of the primary uses of iterators is to allow algorithms to operate generically on containers of various types. Most algorithms take ranges defined by two iteratos as arguments, and perform their operations by traversing the underlying collection. Thus, algorithms do not have to be aware of details of the data structure on which they are operating.

Iterator ranges are by convention expressed by two iterators, first and last, and the range covers all elements in [first, last). That is, the range includes the first element, but not the last element. Therefore, a typical way of visiting every element in a given range is as follows. Assume that the vector in the following example has already been initialized.

OLVector* v;
OLForwardIterator* cur;
OLForwardIterator* end;
id value;

for (cur = [v begin], end = [v end]; ![cur isEqual: end]; [cur advance])
{
    value = [cur dereference];
    // Do something with value...
}

Memory Management

Iterators never retain or attempt to maintain ownership of the container into which they point. Therefore, it is impossible to dispose of a container and continue to use an iterator that refers to it.


ObjectiveLibGenerated Sun Apr 22 15:18:04 2007, © 2004-2007 Will Mason
SourceForge.net Logo