Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-08-24 10:29:15

I've checked in another footnote in iterator_adaptors.htm to explain this.

On Fri, 24 Aug 2001, Jeremy Siek wrote:
jsiek> Actually, footnote 4 explains why the return type is value_type and not
jsiek> reference, but it does not explain why there is only one operator[] and
jsiek> not two. The reason is that it is incorrect to have a non-const operator[]
jsiek> on an iterator. This is a common misconception, because it differs from
jsiek> containers, which should have both const and non-const operator[].
jsiek> Dereferencing an iterator does not change the iterator object (unlike
jsiek> incrementing the iterator) and therefore dereferencing (and also
jsiek> operator[]) should be const methods. Also, a particular iterator type is
jsiek> either mutable or constant, but not both, and the difference between the
jsiek> mutable and constant variaties is that for mutable, the reference type is
jsiek> a non-const reference and for the constant variaties the reference type is
jsiek> const. Remember that the mutable or constantness of the iterator refers to
jsiek> the objects pointed to, not the iterator object itself. Whether the
jsiek> iterator object itself is "const" or not has nothing to do with whether
jsiek> the iterator is mutable or constant.

 Jeremy Siek
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster ( office phone: (812) 855-9761

Boost list run by bdawes at, gregod at, cpdaniel at, john at