https://bugs.documentfoundation.org/show_bug.cgi?id=157665
Bug ID: 157665
Summary: Implement a three-way comparison operator to replace
==, <, >, <=, >=
Product: LibreOffice
Version: 24.2.0.0 alpha0+ Master
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Severity: normal
Priority: medium
Component: LibreOffice
Assignee: [email protected]
Reporter: [email protected]
Since C++20, a three-way comparison operator (a "spaceship" operator <=>) is
available [1].
The codebase uses C++20 since commit 1eef07805021b7ca26a1a8894809b6d995747ba1.
In cases where we have a full set of comparison operators, it could be
beneficial to replace them all with such a three-way operator, to benefit from
code deduplication. Indeed, this needs to take performance into account.
In many cases, the implementation of the operator may also be simplified from
something like
> if (a < other.a)
> ...
> else if (a == other.a && b < other.b)
> ...
into more idiomatic
> return std::tie(a, b) <=> std::tie(other.a, other.b);
Sometimes there is no full set of comparison operators in a class, and only
e.g. operator < is defined. In such cases, the three-way comparison would be
unnecessary; but the simplification of the implementation comparing std::tie
could still be used.
When simplifying the implementations in such a way, performance needs to also
be taken into account: e.g., some calculations should only be performed after
previous comparisons were done, which would not happen, if everything would be
passed to std::tie at once.
This is an easyhack that can be worked on in parallel. Please don't do a
large-scale change over the whole codebase; only change one or two files at a
time. Do not assign this issue to you, because of the parallel nature of the
task.
[1]
https://en.cppreference.com/w/cpp/language/operator_comparison#Three-way_comparison
--
You are receiving this mail because:
You are the assignee for the bug.