Topic: Mutability of associative container keys
Author: Ron <ron.natalie@gmail.com>
Date: Fri, 14 Aug 2009 12:45:51 CST Raw View
On Aug 10, 2:51 am, "Leigh Johnston" <le...@i42.co.uk> wrote:
> Hi,
>
> I propose the following change to the standard:
>
> change 23.2.4.5:
>
> from:
>
> For set and multiset the value type is the same as the key type. For map and
> multimap it is equal to
> pair<const Key, T>. Keys in an associative container are immutable.
>
> to:
>
> For set and multiset the value type is the same as the key type. For map and
> multimap it is equal to
> pair<const Key, T>. Keys in an associative container are immutable with
> regard to their relative sort order within the controlled sequence.
>
I don't like this wording. The requirement is nothing about the
mutability of
the key, but entirely a basis of the comparison function ordering.
The
"mutability" should be deleted and replaced by a different statement
requiring
the ordering to be unchanged. The object itself doesn't necessarily
define
the ordernig, this needs to encompass the Compare function.
--
[ 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 ]
Author: "Leigh Johnston" <leigh@i42.co.uk>
Date: Sat, 15 Aug 2009 13:37:03 CST Raw View
<snip>
>
> I don't like this wording. The requirement is nothing about the
> mutability of
> the key, but entirely a basis of the comparison function ordering.
> The
> "mutability" should be deleted and replaced by a different statement
> requiring
> the ordering to be unchanged. The object itself doesn't necessarily
> define
> the ordernig, this needs to encompass the Compare function.
>
<snip>
Do you want to have a go at suggesting better wording then? Or anybody
else?
/Leigh
--
[ 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 ]
Author: "Joe Smith" <unknown_kev_cat@hotmail.com>
Date: Sun, 16 Aug 2009 01:47:23 CST Raw View
"Ron" <ron.natalie@gmail.com> wrote:
>
> I don't like this wording. The requirement is nothing about the
> mutability of
> the key, but entirely a basis of the comparison function ordering.
> The
> "mutability" should be deleted and replaced by a different statement
> requiring
> the ordering to be unchanged. The object itself doesn't necessarily
> define
> the ordernig, this needs to encompass the Compare function.
>
What about something like the obvious statement that any changes to the
sorting order of keys in an associative container results in undefined
behavior.
I mean, that is the truth. In any sane implementation, the results of such a
change would be that things break in a way that cannot be predicted in the
general case.
A slightly differen qualification would be needed for the unordered
associative containers. In that case having the hash of any key change would
result in undefined behavior.
--
[ 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 ]
Author: "Leigh Johnston" <leigh@i42.co.uk>
Date: Mon, 10 Aug 2009 00:51:28 CST Raw View
Hi,
I propose the following change to the standard:
change 23.2.4.5:
from:
For set and multiset the value type is the same as the key type. For map and
multimap it is equal to
pair<const Key, T>. Keys in an associative container are immutable.
to:
For set and multiset the value type is the same as the key type. For map and
multimap it is equal to
pair<const Key, T>. Keys in an associative container are immutable with
regard to their relative sort order within the controlled sequence.
std::set's elements are not const according to the standard and there is
nothing to stop you adding mutable members to a std::map's keys. I see no
problem in changing a key if it has no effect on its sort order.
/Leigh
--
[ 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 ]