Date: Sat, 28 Nov 2026 16:42:55 -0800
On Saturday, 28 November 2026 10:14:15 Pacific Standard Time Aleksandr
Povaliaev via Std-Proposals wrote:
> I don't like the idea of having two different comparison operators for the
> same Key class.
I agree. A better design would have been to have named members. But that's not
what the authors preferred 30 years ago.
When the class was designed, it was designed with functors and
std::unary_function and std::binary_function. Having two operator() do two
different things depending on whether it's 1-parameter or 2-parameters is a
worse design.
> 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.
We've given one example multiple times: case-insensitive keying of
std::string. You cannot modify std::string, so you have to supply your own
comparator and hasher. You could provide your own MyCaseInsensitiveString
wrapping a std::string, but that's a compromise too.
There are also lots of types that provide equality operators but no hasher.
> 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.
All C structures will come without equality operators. Should they all be
banned from being used as keys in std::map, unordered_map, sets, etc.?
> 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.
I agree it is a good tool to instruct about possible bad design.
We have not agreed this subject is a bad design in the first place. To the
contrary, everyone but you thinks the flexibility is a good design. In fact,
just this week we've discussed whether QHash in Qt 7 should get template
parameters and stop depending on operator== and qHash() - our current thinking
is that indeed we should move in that direction.
I agree there's a danger when the hasher and comparator are not in-sync.
Testing the two functions such that (a == b) → (hash(a) == hash(b)) is ideal,
but I don't know how it can be written in such a way the compiler can prove
it. And that's also not what you're proposing.
> 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).
What does that have to do with anything?
And most Standard Library implementations have either a strict or debugging
mode, or both. It may not do what you're thinking of, but they exist.
Povaliaev via Std-Proposals wrote:
> I don't like the idea of having two different comparison operators for the
> same Key class.
I agree. A better design would have been to have named members. But that's not
what the authors preferred 30 years ago.
When the class was designed, it was designed with functors and
std::unary_function and std::binary_function. Having two operator() do two
different things depending on whether it's 1-parameter or 2-parameters is a
worse design.
> 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.
We've given one example multiple times: case-insensitive keying of
std::string. You cannot modify std::string, so you have to supply your own
comparator and hasher. You could provide your own MyCaseInsensitiveString
wrapping a std::string, but that's a compromise too.
There are also lots of types that provide equality operators but no hasher.
> 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.
All C structures will come without equality operators. Should they all be
banned from being used as keys in std::map, unordered_map, sets, etc.?
> 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.
I agree it is a good tool to instruct about possible bad design.
We have not agreed this subject is a bad design in the first place. To the
contrary, everyone but you thinks the flexibility is a good design. In fact,
just this week we've discussed whether QHash in Qt 7 should get template
parameters and stop depending on operator== and qHash() - our current thinking
is that indeed we should move in that direction.
I agree there's a danger when the hasher and comparator are not in-sync.
Testing the two functions such that (a == b) → (hash(a) == hash(b)) is ideal,
but I don't know how it can be written in such a way the compiler can prove
it. And that's also not what you're proposing.
> 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).
What does that have to do with anything?
And most Standard Library implementations have either a strict or debugging
mode, or both. It may not do what you're thinking of, but they exist.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Data Center - Platform & Sys. Eng.
Received on 2026-11-29 00:43:04
