[Development] C++20 comparisons @ Qt (was: Re: C++20 @ Qt)
Marc Mutz
marc.mutz at qt.io
Fri Sep 22 14:46:27 CEST 2023
On 21.09.23 18:02, Thiago Macieira wrote:
> On Thursday, 21 September 2023 02:10:22 PDT Ivan Solovev via Development
> wrote:
>> But I'd say that if someone wants to implement three-way comparison for
>> their classes in C++17, then a bit better understanding of the language
>> features is a reasonable expectation.
>
> Allowing class developers to implement the three-way comparison such that Qt
> can make use of it is fine. That's basically allowing them to use the same
> technique we will be using to make our classes three-way comparable.
>
> Providing an API for three-way comparison in C++17 does not need to happen.
Where do you draw the line between "Allowing class developers to
implement the three-way comparison such that Qt can make use of it is
fine." and "Providing an API for three-way comparison in C++17 does not
need to happen."?
A Qt class author is supposed to implement a (however named) eq(lhs,
rhs) and cmp(lhs, rhs) function. These functions are then translated into
- in C++17:
- by our macros:
- ==, !=
- <, >, <=, >=
- ==, != (reversed)
- <, >, <=, >= (reversed)
- in C++20:
- by our macros:
- ==
- <=>
- from these, by the compiler:
- !=
- ==, != (reversed)
- <, >, <=, >=
- <, >, <=, >= (reversed)
How is said Qt class author supposed to implement his cmp(lhs, rhs) if
there is no "API" for doing this on his data members? As a concrete
example, how is the author of a `struct QFoo { int; QString; }` supposed
to implement his cmp() if all he gets is op<=>, a C++20-only API?
I don't see how we can manage without an API for doing three-way
comparisons in C++17.
We can try without (4), but (1)-(3) must needs be "semi-public" API (not
in _p.h's).
Thanks,
Marc
--
Marc Mutz <marc.mutz at qt.io>
Principal Software Engineer
The Qt Company
Erich-Thilo-Str. 10 12489
Berlin, Germany
www.qt.io
Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht Charlottenburg,
HRB 144331 B
More information about the Development
mailing list