Date: Fri, 20 Nov 2026 15:50:20 -0500
On Fri, Nov 20, 2026 at 2:21 PM Александр Поваляев via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Colleagues, good morning!
>
> unordered_set container allos "hash" and "compare" functions
> specifications through template arguments. Something like this "unordered_set<string,
> hash<string>, HashCmp> a;". On the other hand there is neither invariant
> specified (in cppreference or any other relevant web resources) for these
> two functions ("hash" and "compare"),
>
Yes there is.
https://eel.is/c++draft/unord.req#general-5.sentence-2
> Two values k1 and k2 are considered equivalent if the container's key
> equality predicate pred(k1, k2) is valid and returns true when passed those
> values. If k1 and k2 are equivalent, the container's hash function shall
> return the same value for both.
(Your example code violates that "shall": strings "abc" and "def" are
equivalent according to your HashCmp, but your hash<string> does *not*
return the same value for both.)
HTH,
Arthur
std-proposals_at_[hidden]> wrote:
> Colleagues, good morning!
>
> unordered_set container allos "hash" and "compare" functions
> specifications through template arguments. Something like this "unordered_set<string,
> hash<string>, HashCmp> a;". On the other hand there is neither invariant
> specified (in cppreference or any other relevant web resources) for these
> two functions ("hash" and "compare"),
>
Yes there is.
https://eel.is/c++draft/unord.req#general-5.sentence-2
> Two values k1 and k2 are considered equivalent if the container's key
> equality predicate pred(k1, k2) is valid and returns true when passed those
> values. If k1 and k2 are equivalent, the container's hash function shall
> return the same value for both.
(Your example code violates that "shall": strings "abc" and "def" are
equivalent according to your HashCmp, but your hash<string> does *not*
return the same value for both.)
HTH,
Arthur
Received on 2026-11-20 20:50:37
