Date: Sat, 28 Nov 2026 21:14:15 +0300
I don't like the idea of having two different comparison operators for the
same Key class.
This is erroneous flexibility - I can't imagine a design pattern which
somehow can explain "having two different comparison operators" - it only
adds a mess.
So, if a particular class being used as an unordered_set template argument
does have a comparison operator == then this operator should be used as
"CompPred", otherwise - don't use the class at all. BUT, as it was written,
we can't just change the interface after 15+ years, so introducing an
appropriate warning is the only game in town.
The same logic is applicable to "Hash" - std::hash<Key> should be used or a
warning should be printed.
Compiler warning is a good tool to inform and to instruct about possible
bad design.
STL library doesn't support debug and information messages :D in general.
We can't just turn of debugging for our lovely STD containers, this is how
STL library works for many years (STLPort was originally to fill the gap
between sandbox student "STL" and real industry applications, but STLPort
has been out of the game for many years).
сб, 28 нояб. 2026 г. в 20:45, Giuseppe D'Angelo via Std-Proposals <
std-proposals_at_[hidden]>:
> Il 28/11/26 15:11, Aleksandr Povaliaev via Std-Proposals ha scritto:
> > I think that we can introduce a compile-time warning: if a Key class has
> > a comparison operator defined, it should be used by default - otherwise
> > a warning is shown.
>
> But ... it *is* used by default? The default template argument for the
> unordered_set's comparator is std::equal_to, which does use the type's
> operator==.
>
> The whole point of the comparator/hashing parameters is to allow extra
> flexibility; in the case of comparisons, whether the underlying type
> already offers an operator== (e.g. string) or not (e.g. span) is
> completely irrelevant. The container allows you to choose the
> comparison/hashing semantics that make sense for your specific use case.
> What's wrong with *that*?
>
> If you're instead complaining about the *engineering* of this feature,
> namely the fact that the unordered containers have two template
> arguments that *must be in sync*, but since they're different arguments
> it's "easy"¹ to get them out of sync and run into UB, that's probably
> fair, but
>
> 1) it needs a *thorough* proposal (= not a short email on this list, but
> an email *with the proposal*) discussing on what is *exactly* the design
> that you want (not "broadly speaking" -- all the nitty gritty the details);
>
> 2) how do you plan to make this deisgn coexist with existing code
> without breaking it in any way shape or form (API and ABI);
>
> 3) if it's really worth to put it in the stdlib considering that you
> could "easily" have something like this in your code:
>
> > template <typename Key, typename Value, typename EqualityAndHasher =
> equal_and_hash<Key>>
> > using my_unordered_map = std::unordered_map<Key, Value, typename
> EqualityAndHasher::Equality, typename EqualityAndHasher::Hasher>;
>
>
>
>
> My 2 c,
>
>
> ¹ [cit. needed], although it's easy to see the parallel with "pass
> pointer and size" vs. "use span"
> --
> Giuseppe D'Angelo
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
same Key class.
This is erroneous flexibility - I can't imagine a design pattern which
somehow can explain "having two different comparison operators" - it only
adds a mess.
So, if a particular class being used as an unordered_set template argument
does have a comparison operator == then this operator should be used as
"CompPred", otherwise - don't use the class at all. BUT, as it was written,
we can't just change the interface after 15+ years, so introducing an
appropriate warning is the only game in town.
The same logic is applicable to "Hash" - std::hash<Key> should be used or a
warning should be printed.
Compiler warning is a good tool to inform and to instruct about possible
bad design.
STL library doesn't support debug and information messages :D in general.
We can't just turn of debugging for our lovely STD containers, this is how
STL library works for many years (STLPort was originally to fill the gap
between sandbox student "STL" and real industry applications, but STLPort
has been out of the game for many years).
сб, 28 нояб. 2026 г. в 20:45, Giuseppe D'Angelo via Std-Proposals <
std-proposals_at_[hidden]>:
> Il 28/11/26 15:11, Aleksandr Povaliaev via Std-Proposals ha scritto:
> > I think that we can introduce a compile-time warning: if a Key class has
> > a comparison operator defined, it should be used by default - otherwise
> > a warning is shown.
>
> But ... it *is* used by default? The default template argument for the
> unordered_set's comparator is std::equal_to, which does use the type's
> operator==.
>
> The whole point of the comparator/hashing parameters is to allow extra
> flexibility; in the case of comparisons, whether the underlying type
> already offers an operator== (e.g. string) or not (e.g. span) is
> completely irrelevant. The container allows you to choose the
> comparison/hashing semantics that make sense for your specific use case.
> What's wrong with *that*?
>
> If you're instead complaining about the *engineering* of this feature,
> namely the fact that the unordered containers have two template
> arguments that *must be in sync*, but since they're different arguments
> it's "easy"¹ to get them out of sync and run into UB, that's probably
> fair, but
>
> 1) it needs a *thorough* proposal (= not a short email on this list, but
> an email *with the proposal*) discussing on what is *exactly* the design
> that you want (not "broadly speaking" -- all the nitty gritty the details);
>
> 2) how do you plan to make this deisgn coexist with existing code
> without breaking it in any way shape or form (API and ABI);
>
> 3) if it's really worth to put it in the stdlib considering that you
> could "easily" have something like this in your code:
>
> > template <typename Key, typename Value, typename EqualityAndHasher =
> equal_and_hash<Key>>
> > using my_unordered_map = std::unordered_map<Key, Value, typename
> EqualityAndHasher::Equality, typename EqualityAndHasher::Hasher>;
>
>
>
>
> My 2 c,
>
>
> ¹ [cit. needed], although it's easy to see the parallel with "pass
> pointer and size" vs. "use span"
> --
> Giuseppe D'Angelo
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-11-28 18:14:31
