Read-Only vs. Read-Write Set Iterators - STL Portability Problems
The set container in the STL must not allow modification of its contained
elements because the element values determine the ordering of the underlying
binary-tree-structure. Depending on the STL implementation this might be
expressed in terms of set iterators being read-only iterators, which imposes
severe restrictions on the usability of the container. In other STL implementations
the set iterators are read-write iterators, which permits inadvertent corruption
of the tree-structure. Both implementation techniques have up- and downsides.
How do we effectively use these different set implementations and still
write portable programs?
One way of coping with the inherent portability trap is implementation
of a simple adapter that hides the differences. Most STL users shy
away from implementing their own iterator types, but is easier than most
developers believe. In this tutorial we see how it can be done and
why it is worth the effort. |
|
PREREQUISITES
|
|
Level:
|
intermediate |
Duration:
|
90 minutes |
Prerequisites:
|
basic knowledge of C++ and the STL |
Presented at:
|
Software Development
,
San Jose, CA, April 2002 |
|