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 3 of 4 Topic 45787 of 47006
Post > Topic >>

Re: constant versus mutable iterator types

by Greg Herlihy <greghe@[EMAIL PROTECTED] > May 6, 2008 at 10:17 PM

On May 6, 9:12=A0pm, Ian Collins <ian-n...@[EMAIL PROTECTED]
> wrote:
> subramanian10...@[EMAIL PROTECTED]
 India wrote:
> > 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.

The salient difference between a std::map and a std::set is that each
value stored in a std::set is also a key. So the reason why values
stored in a std::set are immutable - is because the std::set's keys
are immutable (to ensure a proper order). But since the std::set's
keys and its values are one and the same, it follows that a std::set's
values are immutable because they are also keys..

With a std::map, the values are distinct from their keys - so although
the keys in a std::map are immutable, the values in a map need not be.
Because - unlike a std::set - changing a value stored in a std::map
will not affect the sorted order of the container.

Greg
 




 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 Thu Jul 24 1:59:07 CDT 2008.