Date: Sun, 29 Nov 2026 21:22:35 +0300
Have you read MISRA-C and MISRA-C++ rules?
Most of them are more stupid and seem to be very impractical. But a lot of
companies try to follow these standards.
The same will apply to design pattern decisions. Why do we bother about
putting "{" and "}" brackets after each condition? It will change nothing.
But don't want to introduce a very informative compile-time warning which
informs a user that he is going to use two different comparison operators
for the same structure and possibly hash too.
вс, 29 нояб. 2026 г. в 20:44, Jonathan Wakely <cxx_at_[hidden]>:
>
>
> On Sun, 29 Nov 2026, 05:38 Aleksandr Povaliaev via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> [[[Below]]]...
>>
>>
>> вс, 29 нояб. 2026 г. в 03:43, Thiago Macieira via Std-Proposals <
>> std-proposals_at_[hidden]>:
>>
>>> 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.?
>>>
>>
>> [[[Alex]]] There is no "C POD structure" entity to the C++ program. Since
>> all the structures and classes are declared at once in the header files,
>> they all (including "C POD structure") become C++ class while being
>> included.
>> You should specify an external operator == (POD, POD) and std::hash<POD>
>> "near" the C POD structure declaration, in the same namespace or so.
>>
>
> That's just your opinion, and many people would say it's wrong.
>
> You keep making claims that are not helping to convince anybody. This is
> not a proposal, it doesn't belong here and should be discussed somewhere
> else.
>
>
> AGAIN: I already wrote this example, but would like to repeat it. Please
>> consider the case when you're importing a dynamic and static library where
>> a class is declared but its internal comparison == (POD) operator
>> implementation is hidden. So, the class does have a comparison operator
>> declared, but you don't see its implementation.
>>
>>
>>> > 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.
>>>
>>
>> [[[Alex]]] Really? So, how to turn it on? :)))) I have not seen any
>> warnings or infos from inside STL headers :((
>>
>
Most of them are more stupid and seem to be very impractical. But a lot of
companies try to follow these standards.
The same will apply to design pattern decisions. Why do we bother about
putting "{" and "}" brackets after each condition? It will change nothing.
But don't want to introduce a very informative compile-time warning which
informs a user that he is going to use two different comparison operators
for the same structure and possibly hash too.
вс, 29 нояб. 2026 г. в 20:44, Jonathan Wakely <cxx_at_[hidden]>:
>
>
> On Sun, 29 Nov 2026, 05:38 Aleksandr Povaliaev via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> [[[Below]]]...
>>
>>
>> вс, 29 нояб. 2026 г. в 03:43, Thiago Macieira via Std-Proposals <
>> std-proposals_at_[hidden]>:
>>
>>> 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.?
>>>
>>
>> [[[Alex]]] There is no "C POD structure" entity to the C++ program. Since
>> all the structures and classes are declared at once in the header files,
>> they all (including "C POD structure") become C++ class while being
>> included.
>> You should specify an external operator == (POD, POD) and std::hash<POD>
>> "near" the C POD structure declaration, in the same namespace or so.
>>
>
> That's just your opinion, and many people would say it's wrong.
>
> You keep making claims that are not helping to convince anybody. This is
> not a proposal, it doesn't belong here and should be discussed somewhere
> else.
>
>
> AGAIN: I already wrote this example, but would like to repeat it. Please
>> consider the case when you're importing a dynamic and static library where
>> a class is declared but its internal comparison == (POD) operator
>> implementation is hidden. So, the class does have a comparison operator
>> declared, but you don't see its implementation.
>>
>>
>>> > 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.
>>>
>>
>> [[[Alex]]] Really? So, how to turn it on? :)))) I have not seen any
>> warnings or infos from inside STL headers :((
>>
>
Received on 2026-11-29 18:22:51
