1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 19:37:35 +00:00

Everywhere: Remove redundant inequality comparison operators

C++20 can automatically synthesize `operator!=` from `operator==`, so
there is no point in writing such functions by hand if all they do is
call through to `operator==`.

This fixes a compile error with compilers that implement P2468 (Clang
16 currently). This paper restores the C++17 behavior that if both
`T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be
rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators
makes the rewriting possible again.
See https://reviews.llvm.org/D134529#3853062
This commit is contained in:
Daniel Bertalan 2022-10-21 15:53:20 +02:00 committed by Andrew Kaster
parent 4e406b0730
commit 4296425bd8
40 changed files with 1 additions and 180 deletions

View file

@ -50,7 +50,6 @@ public:
}
bool operator==(SourcePosition const& other) const { return file_path == other.file_path && line_number == other.line_number; }
bool operator!=(SourcePosition const& other) const { return !(*this == other); }
static SourcePosition from_line_info(Dwarf::LineProgram::LineInfo const&);
};

View file

@ -34,7 +34,6 @@ struct FlattenedDeviceTreeReserveEntry {
BigEndian<u64> size;
bool operator==(FlattenedDeviceTreeReserveEntry const& other) const { return other.address == address && other.size == size; }
bool operator!=(FlattenedDeviceTreeReserveEntry const& other) const { return !(operator==(other)); }
};
static_assert(sizeof(FlattenedDeviceTreeReserveEntry) == 16, "FDT Memory Reservation entry size must match specification");

View file

@ -33,11 +33,6 @@ public:
return m_model == other.m_model && m_row == other.m_row && m_column == other.m_column && m_internal_data == other.m_internal_data;
}
bool operator!=(ModelIndex const& other) const
{
return !(*this == other);
}
Model const* model() const { return m_model; }
Variant data(ModelRole = ModelRole::Display) const;

View file

@ -350,11 +350,6 @@ public:
return m_value == other.m_value;
}
constexpr bool operator!=(Color const& other) const
{
return m_value != other.m_value;
}
String to_string() const;
String to_string_without_alpha() const;
static Optional<Color> from_string(StringView);

View file

@ -132,12 +132,6 @@ public:
return x() == other.x() && y() == other.y();
}
template<class U>
[[nodiscard]] bool operator!=(Point<U> const& other) const
{
return !(*this == other);
}
[[nodiscard]] Point<T> operator+(Point<T> const& other) const { return { m_x + other.m_x, m_y + other.m_y }; }
Point<T>& operator+=(Point<T> const& other)

View file

@ -477,12 +477,6 @@ public:
return location() == other.location() && size() == other.size();
}
template<class U>
[[nodiscard]] bool operator!=(Rect<U> const& other) const
{
return !(*this == other);
}
[[nodiscard]] Rect<T> operator*(T factor) const { return { m_location * factor, m_size * factor }; }
Rect<T>& operator*=(T factor)

View file

@ -99,12 +99,6 @@ public:
return width() == other.width() && height() == other.height();
}
template<class U>
[[nodiscard]] constexpr bool operator!=(Size<U> const& other) const
{
return !(*this == other);
}
constexpr Size<T>& operator-=(Size<T> const& other)
{
m_width -= other.m_width;

View file

@ -59,7 +59,6 @@ public:
}
bool operator==(PropertyAttributes const& other) const { return m_bits == other.m_bits; }
bool operator!=(PropertyAttributes const& other) const { return m_bits != other.m_bits; }
[[nodiscard]] u8 bits() const { return m_bits; }

View file

@ -38,11 +38,6 @@ struct Key {
{
return other.key == key && other.modifiers == modifiers;
}
bool operator!=(Key const& other) const
{
return !(*this == other);
}
};
struct KeyCallback {

View file

@ -310,11 +310,6 @@ public:
[&](StringView view) { return view == cstring; });
}
bool operator!=(char const* cstring) const
{
return !(*this == cstring);
}
bool operator==(String const& string) const
{
return m_view.visit(
@ -333,11 +328,6 @@ public:
[&](StringView view) { return view == string; });
}
bool operator!=(StringView other) const
{
return !(*this == other);
}
bool operator==(Utf32View const& other) const
{
return m_view.visit(
@ -349,11 +339,6 @@ public:
[&](StringView view) { return view == RegexStringView { other }.to_string(); });
}
bool operator!=(Utf32View const& other) const
{
return !(*this == other);
}
bool operator==(Utf16View const& other) const
{
return m_view.visit(
@ -363,11 +348,6 @@ public:
[&](StringView view) { return view == RegexStringView { other }.to_string(); });
}
bool operator!=(Utf16View const& other) const
{
return !(*this == other);
}
bool operator==(Utf8View const& other) const
{
return m_view.visit(
@ -377,11 +357,6 @@ public:
[&](StringView view) { return other.as_string() == view; });
}
bool operator!=(Utf8View const& other) const
{
return !(*this == other);
}
bool equals(RegexStringView other) const
{
return other.m_view.visit([this](auto const& view) { return operator==(view); });

View file

@ -118,9 +118,7 @@ public:
[[nodiscard]] bool is_end() const { return !m_current; }
bool operator==(HashIndexIterator const& other) const;
bool operator!=(HashIndexIterator const& other) const { return !(*this == other); }
bool operator==(Key const& other) const;
bool operator!=(Key const& other) const { return !(*this == other); }
HashIndexIterator operator++()
{

View file

@ -63,10 +63,6 @@ struct Attribute {
{
return foreground_color == other.foreground_color && background_color == other.background_color && flags == other.flags;
}
constexpr bool operator!=(Attribute const& other) const
{
return !(*this == other);
}
};
}

View file

@ -43,11 +43,6 @@ public:
return m_type == other.m_type && m_value == other.m_value;
}
bool operator!=(Angle const& other) const
{
return !(*this == other);
}
private:
StringView unit_name() const;

View file

@ -35,8 +35,6 @@ public:
VERIFY_NOT_REACHED();
}
bool operator!=(Display const& other) const { return !(*this == other); }
enum class Outside {
Block,
Inline,

View file

@ -40,11 +40,6 @@ public:
return m_type == other.m_type && m_value == other.m_value;
}
bool operator!=(Frequency const& other) const
{
return !(*this == other);
}
private:
StringView unit_name() const;

View file

@ -121,10 +121,6 @@ public:
// We have a RefPtr<CalculatedStyleValue> member, but can't include the header StyleValue.h as it includes
// this file already. To break the cyclic dependency, we must move all method definitions out.
bool operator==(Length const& other) const;
bool operator!=(Length const& other) const
{
return !(*this == other);
}
float relative_length_to_px(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const;

View file

@ -37,7 +37,6 @@ public:
}
bool operator==(Percentage const& other) const { return m_value == other.m_value; }
bool operator!=(Percentage const& other) const { return !(*this == other); }
private:
float m_value;
@ -147,7 +146,6 @@ public:
return (m_value.template get<Percentage>() == other.m_value.template get<Percentage>());
return (m_value.template get<T>() == other.m_value.template get<T>());
}
bool operator!=(PercentageOr<T> const& other) const { return !(*this == other); }
protected:
bool is_t() const { return m_value.template has<T>(); }

View file

@ -32,11 +32,6 @@ public:
return m_type == other.m_type && m_value == other.m_value;
}
bool operator!=(Resolution const& other) const
{
return !(*this == other);
}
private:
StringView unit_name() const;

View file

@ -109,7 +109,6 @@ public:
float line_height(Layout::Node const&) const;
bool operator==(StyleProperties const&) const;
bool operator!=(StyleProperties const& other) const { return !(*this == other); }
Optional<CSS::Position> position() const;
Optional<int> z_index() const;

View file

@ -402,7 +402,6 @@ public:
virtual String to_string() const = 0;
bool operator==(StyleValue const& other) const { return equals(other); }
bool operator!=(StyleValue const& other) const { return !(*this == other); }
virtual bool equals(StyleValue const& other) const = 0;

View file

@ -41,11 +41,6 @@ public:
return m_type == other.m_type && m_value == other.m_value;
}
bool operator!=(Time const& other) const
{
return !(*this == other);
}
private:
StringView unit_name() const;

View file

@ -35,11 +35,6 @@ public:
return m_node.ptr() == other.m_node.ptr() && m_offset == other.m_offset;
}
bool operator!=(Position const& other) const
{
return !(*this == other);
}
String to_string() const;
private:

View file

@ -106,7 +106,6 @@ public:
}
bool operator==(Origin const& other) const { return is_same_origin(other); }
bool operator!=(Origin const& other) const { return !is_same_origin(other); }
private:
String m_scheme;