diff options
| author | Marc Mutz <[email protected]> | 2025-10-14 09:52:01 +0200 |
|---|---|---|
| committer | Marc Mutz <[email protected]> | 2025-10-15 16:51:11 +0200 |
| commit | 9b4c15ef5ffa94829a0c690eba37472c6833600c (patch) | |
| tree | 01d71122007380193c776bc002152b7fb0e68b58 /src | |
| parent | 104ad65a173e27a54650ef0c165f82e2fdcb2301 (diff) | |
QUndoStack: use idiomatic relational operators
Don't only define the inequality operator. Not even C++20 will
synthesize equality from it. Instead, for C++20, default equality and,
for non-C++20-builds, define inequality in terms of non-equality.
Also =delete qHash(). Equality-comparable types ought to be hashable,
but the code currently doesn't need this feature, so document this by
deleting the qHash overload explicitly. This also prevents 3rd-parties
from defining their own qHash(ActionState), an issue of which we have
had several instances in Qt already, and which can lead to ODR
violations.
Amends 31b0dadb0f371fc94652782c28024f135a0b6f4b.
Pick-to: 6.10 6.8
Task-number: QTBUG-138567
Change-Id: Ib766d44697cb763147eafceb5ffd947206bda979
Reviewed-by: Ivan Solovev <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/util/qundostack_p.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/gui/util/qundostack_p.h b/src/gui/util/qundostack_p.h index fea201ce62d..6bdcf5fb20b 100644 --- a/src/gui/util/qundostack_p.h +++ b/src/gui/util/qundostack_p.h @@ -59,10 +59,17 @@ public: bool enabled = false; QString text; - bool operator!=(const ActionState &other) const noexcept - { - return enabled != other.enabled || text != other.text; - } + friend bool operator==(const ActionState &lhs, const ActionState &rhs) noexcept +#ifdef __cpp_impl_three_way_comparison + = default; +#else + { return lhs.enabled == rhs.enabled && lhs.text == rhs.text; } + friend bool operator!=(const ActionState &lhs, const ActionState &rhs) noexcept + { return !(lhs == rhs); } +#endif + // some compiler's reject seed = 0) = delete, overload instead: + friend void qHash(const ActionState &key, size_t seed) = delete; + friend void qHash(const ActionState &key) = delete; }; QList<QUndoCommand*> command_list; |
