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: associative...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 45767 of 47006
Post > Topic >>

Re: associative containers and algorithms

by Pete Becker <pete@[EMAIL PROTECTED] > May 6, 2008 at 06:42 AM

On 2008-05-06 01:14:12 -0400, "subramanian100in@[EMAIL PROTECTED]
 India" 
<subramanian100in@[EMAIL PROTECTED]
> said:

> I am copying the following lines as it is, from Stanley Lippman's C++
> Primer 4th edition, page 418(First paragraph).
> 
> It says:
> "Although the map and set types provide bidirectional iterators, we
> can use only a subset of the algorithms on associative containers. The
> problem is that key in an associative container is const. Hence, any
> algorithm that writes to elements in the sequence cannot be used on an
> associative container. We may use iterators bound to associative
> containers only to supply arguments that will be read."
> 

While this explanation is technically correct, it's at the wrong level 
of detail. The problem is that modifying elements in an associative 
container could disrupt the ordering of the container. So you aren't 
allowed to do it. In the library's interface that's enforced by making 
the key const and by providing only iterators that don't sup****t 
modifying the elements that they point to.

-- 
  Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The 
Standard C++ Library Extensions: a Tutorial and Reference 
(www.petebecker.com/tr1book)
 




 4 Posts in Topic:
associative containers and algorithms
"subramanian100in@[E  2008-05-05 22:14:12 
Re: associative containers and algorithms
Ian Collins <ian-news@  2008-05-06 18:00:39 
Re: associative containers and algorithms
S S <sarvesh.singh@[EM  2008-05-06 02:19:30 
Re: associative containers and algorithms
Pete Becker <pete@[EMA  2008-05-06 06:42:21 

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:55:33 CDT 2008.