From 4c1d4af2ed8c47bb5251e999dbaf9d1eba460187 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 1 Jan 2025 16:56:20 -0700 Subject: [PATCH] cleanup: use spaceship operator where possible --- common/bspfile_common.cc | 23 +---------------------- include/common/bspfile_common.hh | 3 +-- include/common/qvec.hh | 24 +++--------------------- lightpreview/glview.h | 4 +--- 4 files changed, 6 insertions(+), 48 deletions(-) diff --git a/common/bspfile_common.cc b/common/bspfile_common.cc index b8b46c12..46998458 100644 --- a/common/bspfile_common.cc +++ b/common/bspfile_common.cc @@ -177,30 +177,9 @@ std::string contentflags_t::to_string() const // surfflags_t -static auto as_tuple(const surfflags_t &flags) -{ - return std::tie(flags.native, flags.is_nodraw, flags.is_hintskip, flags.is_hint, flags.no_dirt, flags.no_shadow, - flags.no_bounce, flags.no_minlight, flags.no_expand, flags.no_phong, flags.light_ignore, - flags.surflight_rescale, flags.surflight_style, flags.surflight_color, flags.surflight_minlight_scale, - flags.surflight_atten, flags.surflight_targetname, flags.phong_angle, flags.phong_angle_concave, - flags.phong_group, flags.minlight, flags.minlight_color, flags.light_alpha, flags.light_twosided, - flags.maxlight, flags.lightcolorscale, flags.surflight_group, flags.world_units_per_luxel, - flags.object_channel_mask); -} - bool surfflags_t::needs_write() const { - return as_tuple(*this) != as_tuple(surfflags_t()); -} - -bool surfflags_t::operator<(const surfflags_t &other) const -{ - return as_tuple(*this) < as_tuple(other); -} - -bool surfflags_t::operator>(const surfflags_t &other) const -{ - return as_tuple(*this) > as_tuple(other); + return *this != surfflags_t(); } bool surfflags_t::is_valid(const gamedef_t *game) const diff --git a/include/common/bspfile_common.hh b/include/common/bspfile_common.hh index ff209aa8..85a5892e 100644 --- a/include/common/bspfile_common.hh +++ b/include/common/bspfile_common.hh @@ -320,8 +320,7 @@ struct surfflags_t public: // sort support - bool operator<(const surfflags_t &other) const; - bool operator>(const surfflags_t &other) const; + auto operator<=>(const surfflags_t &other) const = default; bool is_valid(const gamedef_t *game) const; }; diff --git a/include/common/qvec.hh b/include/common/qvec.hh index 89701993..ca128da8 100644 --- a/include/common/qvec.hh +++ b/include/common/qvec.hh @@ -137,12 +137,7 @@ public: [[nodiscard]] constexpr size_t size() const { return N; } // Sort support - [[nodiscard]] constexpr bool operator<(const qvec &other) const { return v < other.v; } - [[nodiscard]] constexpr bool operator<=(const qvec &other) const { return v <= other.v; } - [[nodiscard]] constexpr bool operator>(const qvec &other) const { return v > other.v; } - [[nodiscard]] constexpr bool operator>=(const qvec &other) const { return v >= other.v; } - [[nodiscard]] constexpr bool operator==(const qvec &other) const { return v == other.v; } - [[nodiscard]] constexpr bool operator!=(const qvec &other) const { return v != other.v; } + [[nodiscard]] constexpr auto operator<=>(const qvec &) const = default; [[nodiscard]] constexpr const T &at(const size_t idx) const { @@ -780,17 +775,9 @@ public: { } -private: - auto as_tuple() const { return std::tie(normal, dist); } - public: // Sort support - [[nodiscard]] constexpr bool operator<(const qplane3 &other) const { return as_tuple() < other.as_tuple(); } - [[nodiscard]] constexpr bool operator<=(const qplane3 &other) const { return as_tuple() <= other.as_tuple(); } - [[nodiscard]] constexpr bool operator>(const qplane3 &other) const { return as_tuple() > other.as_tuple(); } - [[nodiscard]] constexpr bool operator>=(const qplane3 &other) const { return as_tuple() >= other.as_tuple(); } - [[nodiscard]] constexpr bool operator==(const qplane3 &other) const { return as_tuple() == other.as_tuple(); } - [[nodiscard]] constexpr bool operator!=(const qplane3 &other) const { return as_tuple() != other.as_tuple(); } + [[nodiscard]] constexpr auto operator<=>(const qplane3 &other) const = default; [[nodiscard]] constexpr const qvec vec4() const { return qvec(normal[0], normal[1], normal[2], dist); } @@ -905,12 +892,7 @@ public: } // Sort support - [[nodiscard]] constexpr bool operator<(const qmat &other) const { return m_values < other.m_values; } - [[nodiscard]] constexpr bool operator<=(const qmat &other) const { return m_values <= other.m_values; } - [[nodiscard]] constexpr bool operator>(const qmat &other) const { return m_values > other.m_values; } - [[nodiscard]] constexpr bool operator>=(const qmat &other) const { return m_values >= other.m_values; } - [[nodiscard]] constexpr bool operator==(const qmat &other) const { return m_values == other.m_values; } - [[nodiscard]] constexpr bool operator!=(const qmat &other) const { return m_values != other.m_values; } + [[nodiscard]] constexpr auto operator<=>(const qmat &other) const = default; // access to elements diff --git a/lightpreview/glview.h b/lightpreview/glview.h index ec4a3811..e4b9fa7a 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -152,9 +152,7 @@ class GLView : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Core float opacity = 1.f; bool alpha_test = false; - auto as_tuple() const { return std::make_tuple(program, texname, opacity, alpha_test); } - - bool operator<(const material_key &other) const { return as_tuple() < other.as_tuple(); } + auto operator<=>(const material_key &other) const = default; }; std::shared_ptr placeholder_texture;