summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRMZeroFour <ritobroto04@gmail.com>2024-03-24 18:57:55 +0530
committerMike Kaganski <mike.kaganski@collabora.com>2024-03-25 13:51:21 +0100
commit6227fccce44e7c44a7a6da707f361b1d4886c1d0 (patch)
tree76e54cdd3e045e1ab495992f3e7c9b1d76010ad2
parent913437f3cd79c4f64151b98366fcc8a90bb66dac (diff)
tdf#157665 Use <=> operator for errcode and strong_int
As part of the efforts in #157665 concerning the spaceship operator for the C++20 codebase upgrade, this commit implements the spaceship operator, replacing redundant operator overloads, in strong_int.hxx and errcode.hxx Change-Id: I23985207c27d6a5147c3f7b4a0d2416f86dec5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165219 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--include/comphelper/errcode.hxx8
-rw-r--r--include/o3tl/strong_int.hxx9
2 files changed, 5 insertions, 12 deletions
diff --git a/include/comphelper/errcode.hxx b/include/comphelper/errcode.hxx
index 000f2c761da9..31c4457db4b5 100644
--- a/include/comphelper/errcode.hxx
+++ b/include/comphelper/errcode.hxx
@@ -24,6 +24,7 @@
#include <ostream>
#include <o3tl/typed_flags_set.hxx>
#include <optional>
+#include <compare>
#if defined(DBG_UTIL)
#if __has_include(<version>)
@@ -94,12 +95,7 @@ public:
explicit operator sal_uInt32() const { return m_value; }
explicit operator bool() const { return m_value != 0; }
- bool operator<(ErrCode const & other) const { return m_value < other.m_value; }
- bool operator<=(ErrCode const & other) const { return m_value <= other.m_value; }
- bool operator>(ErrCode const & other) const { return m_value > other.m_value; }
- bool operator>=(ErrCode const & other) const { return m_value >= other.m_value; }
- bool operator==(ErrCode const & other) const { return m_value == other.m_value; }
- bool operator!=(ErrCode const & other) const { return m_value != other.m_value; }
+ auto operator<=>(ErrCode const & other) const = default;
/** convert to ERRCODE_NONE if it's a warning, else return the error */
ErrCode IgnoreWarning() const {
diff --git a/include/o3tl/strong_int.hxx b/include/o3tl/strong_int.hxx
index 82107955897f..fd7a9abb9c52 100644
--- a/include/o3tl/strong_int.hxx
+++ b/include/o3tl/strong_int.hxx
@@ -24,6 +24,7 @@
#include <limits>
#include <cassert>
#include <type_traits>
+#include <compare>
namespace o3tl
{
@@ -100,12 +101,8 @@ public:
explicit operator bool() const { return m_value != 0; }
UNDERLYING_TYPE get() const { return m_value; }
- bool operator<(strong_int const & other) const { return m_value < other.m_value; }
- bool operator<=(strong_int const & other) const { return m_value <= other.m_value; }
- bool operator>(strong_int const & other) const { return m_value > other.m_value; }
- bool operator>=(strong_int const & other) const { return m_value >= other.m_value; }
- bool operator==(strong_int const & other) const { return m_value == other.m_value; }
- bool operator!=(strong_int const & other) const { return m_value != other.m_value; }
+ auto operator<=>(strong_int const & other) const = default;
+
strong_int& operator++() { ++m_value; return *this; }
strong_int operator++(int) { UNDERLYING_TYPE nOldValue = m_value; ++m_value; return strong_int(nOldValue); }
strong_int& operator--() { --m_value; return *this; }