totally_ordered_wrapper: add reset(P) function

The ctor is explicit so there should not be an assignment operator op=.

Changing the assignment to = Qt::totally_ordered_wrapper(ptr) is also
possible but if ptr is nullptr, I have to forward declare a pointer as
follow "T *n = nullptr" and then call Qt::totally_ordered_wrapper(n).
So I think adding reset(P) function is better.

Found in API Review.

Change-Id: I0acfcacc97a43f3cf8bfa65b2b16a65cae95b727
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit dc49d84abc35dfbbc4028a5f86017786cff13ae7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Rym Bouabid 2024-05-30 12:55:25 +02:00 committed by Qt Cherry-pick Bot
parent 814dc9715b
commit 8d907213ef
2 changed files with 3 additions and 0 deletions

View File

@ -651,6 +651,7 @@ public:
explicit constexpr totally_ordered_wrapper(P p) noexcept : ptr(p) {} explicit constexpr totally_ordered_wrapper(P p) noexcept : ptr(p) {}
constexpr P get() const noexcept { return ptr; } constexpr P get() const noexcept { return ptr; }
constexpr void reset(P p) noexcept { ptr = p; }
constexpr P operator->() const noexcept { return get(); } constexpr P operator->() const noexcept { return get(); }
constexpr T& operator*() const noexcept { return *get(); } constexpr T& operator*() const noexcept { return *get(); }

View File

@ -616,6 +616,8 @@ QT_WARNING_POP
QCOMPARE_NE(Qt::compareThreeWay(b.get(), dWrapper), Qt::strong_ordering::equivalent); QCOMPARE_NE(Qt::compareThreeWay(b.get(), dWrapper), Qt::strong_ordering::equivalent);
QCOMPARE_EQ(Qt::compareThreeWay(bWrapper, nullptr), Qt::strong_ordering::greater); QCOMPARE_EQ(Qt::compareThreeWay(bWrapper, nullptr), Qt::strong_ordering::greater);
QCOMPARE_EQ(Qt::compareThreeWay(nullptr, dWrapper), Qt::strong_ordering::less); QCOMPARE_EQ(Qt::compareThreeWay(nullptr, dWrapper), Qt::strong_ordering::less);
dWrapper.reset(nullptr);
QCOMPARE_EQ(Qt::compareThreeWay(nullptr, dWrapper), Qt::strong_ordering::equivalent);
#undef TEST_BUILTIN #undef TEST_BUILTIN
} }