Skip to content

Commit

Permalink
cleanup: use spaceship operator where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwa committed Jan 1, 2025
1 parent bbe39c7 commit 4c1d4af
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 48 deletions.
23 changes: 1 addition & 22 deletions common/bspfile_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/common/bspfile_common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
24 changes: 3 additions & 21 deletions include/common/qvec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<T, 4> vec4() const { return qvec<T, 4>(normal[0], normal[1], normal[2], dist); }

Expand Down Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions lightpreview/glview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QOpenGLTexture> placeholder_texture;
Expand Down

0 comments on commit 4c1d4af

Please sign in to comment.