From 8039313446397529066
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news3.google.com!news2.google.com!news.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Scott Meyers <smeyers@aristeia.com>
Newsgroups: comp.std.c++
Subject: Immutability of set elements
Date: Sat, 19 Sep 2009 19:08:24 CST
Organization: unknown
Lines: 45
Sender: cppmods@cs.rpi.edu
Approved: james.dennett@gmail.com
Message-ID: <7.0.0.16.2.20090919120102.05e1e878@aristeia.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset="us-ascii"
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Sat, 19 Sep 2009 12:18:06 -0700
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news1.google.com comp.std.c++:1377

The word "immutable" appears exactly once in N2914.  It's at the end
of [associative.reqmts]/5:

 Keys in an associative container are immutable.

Don't be fooled by the general-sounding nature of this edict:  it
really applies only to set.  Keys in a map are already defined to be
const (which presumably implies immutability, but it's hard to say,
because "immutable" in this context is never defined), and the hashed
containers aren't associative containers, they're unordered
associative containers, a completely different thing.  Ahem.  But I
digress.

The sentence above comes straight from the resolution of Library Issue
103, which was opened in 1998 and, from what I can tell, resolved by
2001 ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2001/n1291.html#103
), yet was not incorporated into TC1.  But again I digress.

The commentary on Library Issue 103 says:

>If users need to modify elements, it is possible to use mutable
>members or const_cast.

So here's my question:  what does it mean for a set key to be
immutable?  The commentary on issue 103 suggests that modifying such
keys via mutable members or a const_cast is okay, but presumably doing
so in such a way that would affect the sortedness of the container is
not okay.  Does modifying a set key lead to undefined behavior?  If
so, in all cases, or only under some conditions, e.g., when the
sortedness of the container is affected?

All illumination appreciated.

Thanks,

Scott



--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



