C++ Logo

std-proposals

Advanced search

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

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Sat, 28 Nov 2026 12:09:20 +0000
On Sat, 28 Nov 2026 at 10:53, Aleksandr Povaliaev <apovalyaev_at_[hidden]>
wrote:

> I think the proper way is to use a design like
> *"namespace YYY {*
> *class Key {*
> *public:*
> * operator == () { .... }*
> * ...*
> *};*
> *template<>*
> *class std::hash<Key> {*
> *...*
> *}*
> *}", *where both comparison operator and hash are defined in the same
> place (whether their implementation is hidden in a binary object of
> dynamic/static library or not).
>
> I believe that a "Hash" function should use right the same bits of the Key
> class object, which are used by the comparison operator, or part of them.
>
> Having a separate "CompPred" argument for unordered_set and unordered_map
> only brings mess and increases the possibility of error. It makes sense to
> get rid of it - this is my proposal.
>

That's not a proposal, it's a half-baked idea that is 20 years too late.

Are you proposing to *change* std::unordered_set now? That's not possible,
that's not how a standard works.

We could say that if you use void as the comparison predicate, then it
changes the behaviour of the container. That would be creeping towards an
actual proposal that would be worth discussing.

"It should work differently" is not a proposal.




>
> сб, 28 нояб. 2026 г. в 03:28, Jonathan Wakely <cxx_at_[hidden]>:
>
>>
>>
>> On Fri, 27 Nov 2026, 21:55 Александр Поваляев, <apovalyaev_at_[hidden]>
>> wrote:
>>
>>> The point is that an 'unordered_set' template parameter 'CompPred' is
>>> not needed. It only increases the likelihood of error.
>>>
>>
>> Yes, I understood that some time ago. But as I said, you're at least 15
>> years too late to change unordered_set.
>>
>> Do you actually have a proposal? Because if not, this is the wrong
>> mailing list.
>>
>>
>>

Received on 2026-11-28 12:09:37