Declared in MVector.h
Generic non-constant iterator (pseudo-class) of a collection.
Non-constant iterators are virtually identical in their usage to constant iterators (see CIter), with only a few differences:
- The dereferencing operator* (unary *) returns a non-constant reference, which allows to modify the collection's item to which this iterator is pointing (a constant iterator does not allow it)
- The init constructor Iter::Iter(Collection&) receives a non-constant reference to a collection instead of a constant one, but that's usually not noticeable
- Unlike constant iterator, the init constructor of Iter can fail due to insufficient memory, because it mat have to unshare the collection. In such a case, the resulting iterator is invalid and not owned. This is necessary, because a shared collection cannot be edited. Constant iterators do not cause unsharing - they can be used on shared collections as well. See Collection::operator= for more info regarding the sharing
- Non-constant iterators make their owner collection "unshareable" (unlike constant iterators). If a collection that owns non-constant iterators is copied, then the copy will be a full (slow) copy, not shared copy. It is therefore recommended to use the constant iterators whenever possible, and use reset function on non-constant iterators before copying their owner collection
Not all collections have a non-constant iterator, because in some collections, such as MHash, the location of the item depends on its value, so changing the value of an item would break the collection's consistency. Only 4 collections have a non-constant iterator: MVector, MMap, MList, and MImage.
Let us know
Please Contact us to report any errors on this page, or to suggest any improvements.