From -5786681545251443064
X-Google-Thread: 7894ca11fe,dcc43f3425b0e139
X-Google-Attributes: gid7894ca11fe,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 20 Sep 2009 10:20:02 -0500
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
To: (Usenet)
From: "Bo Persson" <bop@gmb.dk>
Newsgroups: comp.std.c++
Subject: Re: Immutability of set elements
Organization: unknown
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <7hmbfoF2uc89oU1@mid.individual.net>
References: <7.0.0.16.2.20090919120102.05e1e878@aristeia.com>
X-Original-Date: Sun, 20 Sep 2009 11:38:10 +0200
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Date: Sun, 20 Sep 2009 10:14:24 CST
Lines: 40
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-wmRxWnlVbsTo0VAbMCoqN/Ds+2pBgqhzinPzJy55MfugI5qarelnqEvcQCEvGW68ejZwULM4THpncyZ!1KwmCyetDYshlrRk4T6i7wY8LzK8+kw5Y63x2zuvTdEKcBjkaa5wJT52X2AkyA==
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Xref: g2news2.google.com comp.std.c++:1378

Scott Meyers wrote:
>
>> 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?
>

 From what I understand, some people would like to have the possibility
of updating parts of the stored data, that is not actually part of the
key. With a user supplied comparison-functor, parts of a stored
structure might have no effect on the ordering.

For example, you might have an existing data structure that already
contains the key value. Ordinarily you would store this in a map, but
to avoid storing the key twice, you use a set with a special
comparator.

Anyone actually doing this, is supposedly skilled enough to use a
proper const_cast when updating the non-key data.  :-)


Bo Persson



-- 
[ 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                      ]



