Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: constant ve...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 45787 of 47032
Post > Topic >>

Re: constant versus mutable iterator types

by Ian Collins <ian-news@[EMAIL PROTECTED] > May 7, 2008 at 04:12 PM

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.
 




 4 Posts in Topic:
constant versus mutable iterator types
"subramanian100in@[E  2008-05-06 20:51:52 
Re: constant versus mutable iterator types
Ian Collins <ian-news@  2008-05-07 16:12:17 
Re: constant versus mutable iterator types
Greg Herlihy <greghe@[  2008-05-06 22:17:27 
Re: constant versus mutable iterator types
dizzy <dizzy@[EMAIL PR  2008-05-07 11:05:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:21:30 CDT 2008.