Definition
Instances of type it iterate over the elements of a key set. They behave similar to const-pointers to AgdKey. The elements of a key set are always in the same order as the keys in its keymapper. A key set S provides functions to retrieve iterators pointing to the first or last element of S. We say an iterator of key set S is valid iff it points to an element of S. Derefferencing is only allowed for valid iterators.
#include < AGD/KeySet.h >
Creation
| KeySet::const_iterator | it | creates an invalid iterator it. |
| KeySet::const_iterator | it(const KeySet& S) | creates an iterator it pointing to the first element of S. |
| KeySet::const_iterator | it(const const_iterator& iter) | |
| creates an iterator identical to iter. | ||
Operations
| bool | it.valid() | returns true iff it is valid, i.e., points to an element. |
| bool | it == const const_iterator& iter | |
| returns true iff it and iter point to the same element. | ||
| bool | it != const const_iterator& iter | |
| returns true iff it and iter point to different elements. | ||
| const_iterator & | it = const const_iterator& iter | |
| assigns iter to it. | ||
| const AgdKey & | *it | returns the element to which it points. |
| const AgdKey * | it-> | returns the address of the element to which it points. |
| const_iterator & | ++it | increments and returns it. |
| const_iterator | it++ | increments it and returns its previous value. |
| const_iterator & | -it | decrements and returns it. |
| const_iterator | it- | decrements it and returns its previous value. |
Example
The following examples shows, how to use key set iterators in order to iterate over all elements of a key set. The second loop iterates in reverse order and demonstrates the use of operator->.
void write_set (const KeySet &S)
{
KeySet::const_iterator it;
// iteration over all elements of S
for (it = S.begin(); it != S.end(); ++it) {
cout << *it << endl;
}
// iteration in reverse order
for (it = S.rbegin(); it != S.rend(); --it) {
cout << it->index() << endl;
}
}
© Copyright 1998-2001, Algorithmic Solutions Software GmbH. All rights reserved.
2001-08-13