subramanian100in@[EMAIL PROTECTED]
India wrote:
> I am reading David Musser's "STL Tutorial and Reference Guide" Second
> Edition.
> In that book, on pages 68-69, definition has been given that "an
> iterator can be mutable or constant depending on whether the result of
> operator* is a reference or a constant reference."
>
> As per this definition, on page 71 in this book, it is mentioned that
> for 'set' and 'multiset', both the iterator and const_iterator types
> are constant bidirectional types - in fact they are the same type.
>
> The reason given in this book is as follows:
>
> set<int> s;
> s.insert(3);
> s.insert(5);
> s.insert(7);
> set<int>::iterator i = s.begin();
> *i = 4; // incorrect
>
> On page 72, it is given that for container set<T>, set<T>::iterator is
> constant bidirectional iterator category and for container
> multiset<T>, multiset<T>::iterator is constant bidirectional iterator
> category.
>
> My understanding:
> Along the same above discussion, shouldn't map<Key, T>::iterator and
> multimap<Key, T>::iterator also be constant bidirectional iterators ?
> (This is what I expected because for both set, multiset, map,
> multimap, the key is constant)
>
No, the key may be constant, but the value is mutable.
--
Ian Collins.


|