From -8441578401696501421
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c6e0f35f0f156cba
X-Google-Attributes: gidf78e5,public
From: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Subject: Re: Viewing the contents of a const map&
Date: 1999/03/20
Message-ID: <36F217C4.4A668F7@physik.tu-muenchen.de>#1/1
X-Deja-AN: 456791043
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <36eff78c.407264815@news1.occa.home.net> <7cq66i$4fc$1@remarQ.com>
X-Original-Date: Fri, 19 Mar 1999 10:24:20 +0100
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 921905193 20237 128.250.29.17 (20 Mar 1999 04:46:33 GMT)
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANvMoD+EDnX0m9pzZAQESewF9EwjIz1wb5+09JG/XrxgiTSADuqMEQWg6 u9kAgKvWAV7VbPVQ24z2rdkbkJA2aTCs =2Gt3
Mime-Version: 1.0
NNTP-Posting-Date: 20 Mar 1999 04:46:33 GMT
Newsgroups: comp.std.c++

Joe Buck wrote:
> 
> sean.shubin@www.anything.com (Sean Shubin) writes:
> >Since the map operator [] can be used for both reading and writing
> >values to a map, what should I use to access a given value of a map
> >that is const?
> 
> The reason you can't use [] with a const map is because there isn't
> anything that can be done if the key is not present in the map
> (well, OK, you could throw an exception).

If the const operator[] returned by value, it could also return
a default constructed value. This is what the non-const operator[]
does as well, except that it puts that into the map as well.
If you use only the operator[] interface, you even won't see
the difference at all. If you are using the iterator interface,
you'll see the difference, of course - but since it's logical
that a const operator[] won't change the map, I don't see a
problem with this.

[...]
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



