![]() |
Site Archive (Complete) | |||
|
ABOUT US |
CONTACT |
ADVERTISE |
SUBSCRIBE |
SOURCE CODE |
CURRENT PRINT ISSUE |
NEWSLETTERS
|
RESOURCES
|
BLOGS
|
PODCASTS
|
CAREERS
|
||||
October 01, 2000
Are Set Iterators Mutable or Immutable?Klaus Kreft
The C++ Standard mandates that containers such as std::set provide both mutable and immutable iterators. Unfortunately, mutable iterators turn out to be dangerous when used with sets. If you use one to modify an element of a set, you risk corrupting the underlying data structure. Langer and Kreft explain why this is so, and they discuss some of the less-than-desirable solutions - including non-portable implementations of the standard library. The authors then propose a more sensible, and portable, solution using iterator adapters.
Figure 1: The remove algorithms do not remove anything
|
|
||||||||||||||||||||||||||
|
|