Date: Thu, 26 Nov 2026 09:32:24 +0100
Il 25/11/26 19:43, Jonathan Wakely via Std-Proposals ha scritto:
> In your example, what if you did std::unordered_set<std::string,
> case_insensitive_hash<std::string>>? You would have a hash function
> which ignores case, but it would still use std::equal_to<std::string>
> which is case-sensitive. You would probably end up with undefined
> behaviour. If the unordered containers took a single type which is
> responsible for both hashing and equality, that couldn't happen.
I guess you meant a case insensitive equality, but case sensitive
hashing? Because otherwise the above would work: two strings that are
equal (case sensitively) also hash equal (case insensitively).
But I agree with you that this is the point OP wanted to make -- have
one customization point centralizes the code and possibly reduces the
risk of hashing and equality being inconsistent.
On the other hand, I also disagree; indeed sometimes one *wants* the
extra flexibility (I've myself used e.g. different hashing functions for
strings, f.i. just hashing up to the first N characters). If this
requires assembling two arbitrary behaviors in the single customization
point, that's no different from we have today.
My 2 c,
--
Giuseppe D'Angelo
> In your example, what if you did std::unordered_set<std::string,
> case_insensitive_hash<std::string>>? You would have a hash function
> which ignores case, but it would still use std::equal_to<std::string>
> which is case-sensitive. You would probably end up with undefined
> behaviour. If the unordered containers took a single type which is
> responsible for both hashing and equality, that couldn't happen.
I guess you meant a case insensitive equality, but case sensitive
hashing? Because otherwise the above would work: two strings that are
equal (case sensitively) also hash equal (case insensitively).
But I agree with you that this is the point OP wanted to make -- have
one customization point centralizes the code and possibly reduces the
risk of hashing and equality being inconsistent.
On the other hand, I also disagree; indeed sometimes one *wants* the
extra flexibility (I've myself used e.g. different hashing functions for
strings, f.i. just hashing up to the first N characters). If this
requires assembling two arbitrary behaviors in the single customization
point, that's no different from we have today.
My 2 c,
--
Giuseppe D'Angelo
Received on 2026-11-26 08:32:32
