From -7278729549768733763
X-Google-Thread: f78e5,d50382f3e5ec6b4e
X-Google-Thread: 109fba,d50382f3e5ec6b4e
X-Google-Attributes: gidf78e5,gid109fba,public
X-Google-Language: ENGLISH,ASCII
Path: g2news1.google.com!news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!news-in.ntli.net!newsrout1-win.ntli.net!ntli.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: jdennett@acm.org (James Dennett)
Newsgroups: comp.std.c++,comp.lang.c++
Subject: Re: The issue of const maps and operator[]
Date: Thu,  2 Dec 2004 06:51:23 GMT
Organization: Cox Communications
Lines: 42
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <YWxrd.191852$hj.44035@fed1read07>
References: <3171vsF37jfq7U1@individual.net>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: news.demon.co.uk 1101970296 2037 158.152.254.254 (2 Dec 2004 06:51:36 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 2 Dec 2004 06:51:36 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040616
X-MIME-Autoconverted: from 8bit to quoted-printable by mulga.cs.mu.OZ.AU id iB26pXBn010113
X-Accept-Language: en-us, en
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
X-Path: comp-std-cpp-robomod!not-for-mail
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id iB26pNhI010090;
	Thu, 2 Dec 2004 17:51:23 +1100 (EST)
X-NNTP-Posting-Date: Thu, 02 Dec 2004 00:42:16 EST
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: fed1read07.mgt.cox.net: news set sender to newsmaster@cox.net using -f
X-Newsgroups: comp.std.c++,comp.lang.c++
Xref: g2news1.google.com comp.std.c++:3547 comp.lang.c++:32388

Ney Andr=E9 de Mello Zunino wrote:

> Hello.
>=20
> Searching around before posting this message revealed that the issue ha=
s=20
> been brought up a significant number of times (here are two related=20
> threads [1] [2]). So /std::map<>/ does not provide a const version of=20
> its /operator[]/ member function because that function is supposed to=20
> modify the map in case the passed key is not present. The question whic=
h=20
> follows is: why not provide a const overload which would throw when the=
=20
> given key would not exist?=20

Because it would violate the important principle that adding
const to code should not change its behaviour (except for
propogation of constness to other code), although it may
cause it to no longer compile.  The language doesn't enforce
that in isolation; good library design is also necessary.

> It seems like a natural and easy-to-implement=20
> solution which would contribute to map's associative array role.

But it's too fragile, for the reason above.

> In spite of having found several discussions on this topic, I could not=
=20
> find mention of whether this issue is going to be addressed when C++=20
> gets its next major revision.=20

I find it enormously unlikely that this would be changed in the
next revision of C++.

-- James

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



