[Development] C++20 comparisons @ Qt (was: Re: C++20 @ Qt)
Marc Mutz
marc.mutz at qt.io
Fri Nov 4 16:15:39 CET 2022
Hi Ulf,
On 04.11.22 12:13, Ulf Hermann via Development wrote:
> One thing I haven't understood about the ordering problem is why we
> cannot just define our "invalid" values to always be < any valid one and
> equal to other invalid ones. This way we get at least weak ordering for
> all our types and we're done.
That's what we're currently doing, yes. At least for QDateTime. For
QString, we have that isNull() compares equal to empty. Each class has
it's own semantics. I'll have a look at QTypeRevision, but that prompted
me to remember QOperatingSystemVersion, where we really, genuinely have
several sets of values where elements from different sets are not
ordered (Win10 <? OSX13), and Win op OSX is always false, for all op.
There, partial_ordering is consistent with the current implementation.
We don't _need_ to make invalid values unordered, but it would be the
mathematically correct thing to do. We removed QVariant::op< because of
these problems. partial_ordering would allow to bring it back.
> There may be types where existing operator< work differently (*cough*
> QTypeRevision), but that just means we need to emulate that same
> behavior with the new operators.
Without having looked at QTypeRevision, I agree in general.
> Indeed the NaN behavior has always been a pain to deal with every time
> I've encountered it. If we have a chance to avoid it, we should.
>
> What is the downside of such an approach?
The (potential) downside is that it's arbitrary and classes might behave
inconsistently (one sorts invalid before valid ones, the other vice
versa). It may also be a bit more work to document (unless we choose not
to mention that little detail). Or we can't reap any future tool support
that might be developed for partial_ordering (sanitizers, etc).
Overall, I don't feel strongly about it (no pun intended). From the
ongoing discussion more and more examples pop up, though, where
partial_ordering would be a really good idea (QVariant, QOSVersion,
QTypeRevision?), and if those definite use-cases make people more
familiar with partial_ordering, maybe invalid-as-unorderable would also
come to be felt as more natural.
Thanks,
Marc
More information about the Development
mailing list