C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Q: invariant for unordered_set and unordered_map "hash" and "comp" argument

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 28 Nov 2026 16:53:07 -0800
On Saturday, 28 November 2026 16:19:07 Pacific Standard Time Aleksandr
Povaliaev via Std-Proposals wrote:
> 4) having two comparison operators for the same class is a potential source
> of errors and misunderstanding (this is what I am talking about);

Agreed that it can be a potential source of errors, if misused.

I even agree with you that clean design should use the class's own operator==
and should not compare a portion of the object. But my point of view is just
that: my opinion. Others have other reasons.

It's also a flexibility that is very much wanted.

I can readily see motivations where you'd want to deploy your comparator and
hasher for a portion of the object: for example, when you're given a large(r)
object you must store anyway, but whose uniqueness in the set in question is a
subset of the object's identity. And as a specific example, think of struct
sockaddr_in6: in most cases, port number and address are sufficient condition
for uniqueness and you do not need to compare the sin6_flowinfo field.

Then there's the case where you must provide those because the type in
question didn't provide them at the time you began using them. Now maybe it
does - should your code suddenly begin producing warnings?

Restricting the flexibility of other users and uses needs to be for a very good
reason. And you have not provided one.

> So, there is still some room for improvement. And after all, I've not
> proposed any changes to 'unordered_set' and 'unordered_map' interfaces.
> Where did you see it? I just wrote about invariants, assertions and
> warnings from the very beginning.

The fact that you're posting to the Standard *Proposals* mailing list. We
expect you to either have a proposal or an idea for one, which we could then
help shape, or discuss someone else's proposal.

Maybe you should have tried the Standard Discussion mailing list, or one of
many other C++ discussion forums such as the Cpplang Slack.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-11-29 00:53:12