TITLE: Constness, containers, and iterators [ This came in response to discussions about dealing with both const and non-const containers with iterators. In particular, handling both const and non-const containers seems to imply having two iterator kinds. -adc ] RESPONSE: michael@selway.umt.edu (Michael Babcock) Is there a standard solution to this problem? Any hints will be greatly appreciated. The only thing I can think of is to have two separate iterator classes, the normal one and another one just for when I need to manipulate the list being iterated. RESPONSE: fjh@munta.cs.mu.OZ.AU (Fergus Henderson), 18 Sep 94 There are two standard solutions. The first is the one you mention, the second is to use index-style iterators rather than pointer-style iterators. Then you only need one iterator class, because you can overload the `[]' operator on const. Collection c; // ... for (Iterator i = c.first(); c.valid(i); c.next(i)) { c[i] = 42; // calls `Collection::operator[](Iterator)' } const Collection const_c; // ... for (Iterator i = const_c.first(); const_c.valid(i); const_c.next(i)) { cout << const_c[i]; // calls `Collection::operator[](Iterator) const' }