Default comparison operators that can be

This commit is contained in:
Maxime Coste 2023-10-25 21:06:52 +11:00
parent 96884193dd
commit 2fa55be40a
12 changed files with 17 additions and 45 deletions

View File

@ -28,10 +28,7 @@ struct JumpList
const SelectionList& backward(Context& context, int count); const SelectionList& backward(Context& context, int count);
void forget_buffer(Buffer& buffer); void forget_buffer(Buffer& buffer);
friend bool operator==(const JumpList& lhs, const JumpList& rhs) friend bool operator==(const JumpList& lhs, const JumpList& rhs) = default;
{
return lhs.m_jumps == rhs.m_jumps and lhs.m_current == rhs.m_current;
}
size_t current_index() const { return m_current; } size_t current_index() const { return m_current; }

View File

@ -33,13 +33,7 @@ struct Face
Attribute attributes = Attribute::Normal; Attribute attributes = Attribute::Normal;
Color underline = Color::Default; Color underline = Color::Default;
friend constexpr bool operator==(const Face& lhs, const Face& rhs) friend constexpr bool operator==(const Face& lhs, const Face& rhs) = default;
{
return lhs.fg == rhs.fg and
lhs.bg == rhs.bg and
lhs.underline == rhs.underline and
lhs.attributes == rhs.attributes;
}
friend constexpr size_t hash_value(const Face& val) friend constexpr size_t hash_value(const Face& val)
{ {

View File

@ -38,7 +38,7 @@ struct TestableFlags
constexpr operator Flags() const { return value; } constexpr operator Flags() const { return value; }
constexpr operator UnderlyingType<Flags>() const { return (UnderlyingType<Flags>)value; } constexpr operator UnderlyingType<Flags>() const { return (UnderlyingType<Flags>)value; }
constexpr bool operator==(const TestableFlags<Flags>& other) const { return value == other.value; } constexpr bool operator==(const TestableFlags<Flags>& other) const = default;
}; };
template<WithBitOps Flags> template<WithBitOps Flags>

View File

@ -10,12 +10,12 @@ namespace Kakoune
void register_highlighters(); void register_highlighters();
struct InclusiveBufferRange{ BufferCoord first, last; }; struct InclusiveBufferRange
inline bool operator==(const InclusiveBufferRange& lhs, const InclusiveBufferRange& rhs)
{ {
return lhs.first == rhs.first and lhs.last == rhs.last; BufferCoord first, last;
} friend bool operator==(const InclusiveBufferRange& lhs, const InclusiveBufferRange& rhs) = default;
};
String option_to_string(InclusiveBufferRange range); String option_to_string(InclusiveBufferRange range);
InclusiveBufferRange option_from_string(Meta::Type<InclusiveBufferRange>, StringView str); InclusiveBufferRange option_from_string(Meta::Type<InclusiveBufferRange>, StringView str);

View File

@ -25,8 +25,7 @@ struct InsertCompleterDesc
Line Line
}; };
bool operator==(const InsertCompleterDesc& other) const bool operator==(const InsertCompleterDesc& other) const = default;
{ return mode == other.mode and param == other.param; }
Mode mode; Mode mode;
Optional<String> param; Optional<String> param;

View File

@ -88,12 +88,6 @@ Vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t
return res; return res;
} }
bool operator==(const LineModification& lhs, const LineModification& rhs)
{
return lhs.old_line == rhs.old_line and lhs.new_line == rhs.new_line and
lhs.num_removed == rhs.num_removed and lhs.num_added == rhs.num_added;
}
void LineRangeSet::update(ConstArrayView<LineModification> modifs) void LineRangeSet::update(ConstArrayView<LineModification> modifs)
{ {
if (modifs.empty()) if (modifs.empty())

View File

@ -20,6 +20,8 @@ struct LineModification
LineCount num_added; // number of lines added (including this one) LineCount num_added; // number of lines added (including this one)
LineCount diff() const { return new_line - old_line + num_added - num_removed; } LineCount diff() const { return new_line - old_line + num_added - num_removed; }
friend bool operator==(const LineModification& lhs, const LineModification& rhs) = default;
}; };
Vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t timestamp); Vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t timestamp);

View File

@ -58,10 +58,7 @@ struct PrefixedList
P prefix; P prefix;
Vector<T, MemoryDomain::Options> list; Vector<T, MemoryDomain::Options> list;
friend bool operator==(const PrefixedList& lhs, const PrefixedList& rhs) friend bool operator==(const PrefixedList& lhs, const PrefixedList& rhs) = default;
{
return lhs.prefix == rhs.prefix and lhs.list == rhs.list;
}
}; };
template<typename T> template<typename T>

View File

@ -10,11 +10,7 @@ struct Range
T begin; T begin;
T end; T end;
friend bool operator==(const Range& lhs, const Range& rhs) friend bool operator==(const Range& lhs, const Range& rhs) = default;
{
return lhs.begin == rhs.begin and lhs.end == rhs.end;
}
friend size_t hash_value(const Range& range) friend size_t hash_value(const Range& range)
{ {

View File

@ -510,11 +510,7 @@ struct ConcatView
Iterator& operator++() { if (is2()) ++m_it2; else ++m_it1; return *this; } Iterator& operator++() { if (is2()) ++m_it2; else ++m_it1; return *this; }
Iterator operator++(int) { auto copy = *this; ++*this; return copy; } Iterator operator++(int) { auto copy = *this; ++*this; return copy; }
friend bool operator==(const Iterator& lhs, const Iterator& rhs) friend bool operator==(const Iterator& lhs, const Iterator& rhs) = default;
{
return lhs.m_it1 == rhs.m_it1 and lhs.m_end1 == rhs.m_end1 and
lhs.m_it2 == rhs.m_it2;
}
private: private:
bool is2() const { return m_it1 == m_end1; } bool is2() const { return m_it1 == m_end1; }

View File

@ -60,7 +60,7 @@ struct MatchResults
iterator& operator++() { m_it += 2; return *this; } iterator& operator++() { m_it += 2; return *this; }
SubMatch operator*() const { return {*m_it, *(m_it+1)}; } SubMatch operator*() const { return {*m_it, *(m_it+1)}; }
friend bool operator==(const iterator& lhs, const iterator& rhs) { return lhs.m_it == rhs.m_it; } friend bool operator==(const iterator& lhs, const iterator& rhs) = default;
private: private:
It m_it; It m_it;
@ -83,10 +83,7 @@ struct MatchResults
SubMatch{m_values[i*2], m_values[i*2+1]} : SubMatch{}; SubMatch{m_values[i*2], m_values[i*2+1]} : SubMatch{};
} }
friend bool operator==(const MatchResults& lhs, const MatchResults& rhs) friend bool operator==(const MatchResults& lhs, const MatchResults& rhs) = default;
{
return lhs.m_values == rhs.m_values;
}
void swap(MatchResults& other) void swap(MatchResults& other)
{ {

View File

@ -68,7 +68,7 @@ struct TerminalUI::Window::Line
text.resize(it - text.begin(), 0); text.resize(it - text.begin(), 0);
} }
friend bool operator==(const Atom& lhs, const Atom& rhs) { return lhs.text == rhs.text and lhs.skip == rhs.skip and lhs.face == rhs.face; } friend bool operator==(const Atom& lhs, const Atom& rhs) = default;
friend size_t hash_value(const Atom& atom) { return hash_values(atom.text, atom.skip, atom.face); } friend size_t hash_value(const Atom& atom) { return hash_values(atom.text, atom.skip, atom.face); }
}; };