summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-10-25 21:06:52 +1100
committerMaxime Coste <mawww@kakoune.org>2023-10-25 21:06:52 +1100
commit2fa55be40a787be71f4360fd4e36b7a790c74fa6 (patch)
tree4ba6c0bc844f2d4ce6a004ae71ef52aa21f95448
parent96884193ddad76530a09a1b095180b0ca8257b7c (diff)
Default comparison operators that can be
-rw-r--r--src/context.hh5
-rw-r--r--src/face.hh8
-rw-r--r--src/flags.hh2
-rw-r--r--src/highlighters.hh10
-rw-r--r--src/insert_completer.hh3
-rw-r--r--src/line_modification.cc6
-rw-r--r--src/line_modification.hh2
-rw-r--r--src/option.hh5
-rw-r--r--src/range.hh6
-rw-r--r--src/ranges.hh6
-rw-r--r--src/regex.hh7
-rw-r--r--src/terminal_ui.cc2
12 files changed, 17 insertions, 45 deletions
diff --git a/src/context.hh b/src/context.hh
index 846855a2..fca4ba06 100644
--- a/src/context.hh
+++ b/src/context.hh
@@ -28,10 +28,7 @@ struct JumpList
const SelectionList& backward(Context& context, int count);
void forget_buffer(Buffer& buffer);
- friend bool operator==(const JumpList& lhs, const JumpList& rhs)
- {
- return lhs.m_jumps == rhs.m_jumps and lhs.m_current == rhs.m_current;
- }
+ friend bool operator==(const JumpList& lhs, const JumpList& rhs) = default;
size_t current_index() const { return m_current; }
diff --git a/src/face.hh b/src/face.hh
index bbe8031a..1ed986ef 100644
--- a/src/face.hh
+++ b/src/face.hh
@@ -33,13 +33,7 @@ struct Face
Attribute attributes = Attribute::Normal;
Color underline = Color::Default;
- friend constexpr bool operator==(const Face& lhs, const Face& rhs)
- {
- return lhs.fg == rhs.fg and
- lhs.bg == rhs.bg and
- lhs.underline == rhs.underline and
- lhs.attributes == rhs.attributes;
- }
+ friend constexpr bool operator==(const Face& lhs, const Face& rhs) = default;
friend constexpr size_t hash_value(const Face& val)
{
diff --git a/src/flags.hh b/src/flags.hh
index 4cecd5a5..178f59e6 100644
--- a/src/flags.hh
+++ b/src/flags.hh
@@ -38,7 +38,7 @@ struct TestableFlags
constexpr operator Flags() const { return 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>
diff --git a/src/highlighters.hh b/src/highlighters.hh
index f68f0b26..c8f1dd22 100644
--- a/src/highlighters.hh
+++ b/src/highlighters.hh
@@ -10,12 +10,12 @@ namespace Kakoune
void register_highlighters();
-struct InclusiveBufferRange{ BufferCoord first, last; };
-
-inline bool operator==(const InclusiveBufferRange& lhs, const InclusiveBufferRange& rhs)
+struct InclusiveBufferRange
{
- 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);
InclusiveBufferRange option_from_string(Meta::Type<InclusiveBufferRange>, StringView str);
diff --git a/src/insert_completer.hh b/src/insert_completer.hh
index d7fb5967..cce433a2 100644
--- a/src/insert_completer.hh
+++ b/src/insert_completer.hh
@@ -25,8 +25,7 @@ struct InsertCompleterDesc
Line
};
- bool operator==(const InsertCompleterDesc& other) const
- { return mode == other.mode and param == other.param; }
+ bool operator==(const InsertCompleterDesc& other) const = default;
Mode mode;
Optional<String> param;
diff --git a/src/line_modification.cc b/src/line_modification.cc
index f63bc6ea..5b5f523d 100644
--- a/src/line_modification.cc
+++ b/src/line_modification.cc
@@ -88,12 +88,6 @@ Vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t
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)
{
if (modifs.empty())
diff --git a/src/line_modification.hh b/src/line_modification.hh
index b9c9cfcd..75bacdbd 100644
--- a/src/line_modification.hh
+++ b/src/line_modification.hh
@@ -20,6 +20,8 @@ struct LineModification
LineCount num_added; // number of lines added (including this one)
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);
diff --git a/src/option.hh b/src/option.hh
index d7f75431..732fefca 100644
--- a/src/option.hh
+++ b/src/option.hh
@@ -58,10 +58,7 @@ struct PrefixedList
P prefix;
Vector<T, MemoryDomain::Options> list;
- friend bool operator==(const PrefixedList& lhs, const PrefixedList& rhs)
- {
- return lhs.prefix == rhs.prefix and lhs.list == rhs.list;
- }
+ friend bool operator==(const PrefixedList& lhs, const PrefixedList& rhs) = default;
};
template<typename T>
diff --git a/src/range.hh b/src/range.hh
index 696e5010..a36386f2 100644
--- a/src/range.hh
+++ b/src/range.hh
@@ -10,11 +10,7 @@ struct Range
T begin;
T end;
- friend bool operator==(const Range& lhs, const Range& rhs)
- {
- return lhs.begin == rhs.begin and lhs.end == rhs.end;
- }
-
+ friend bool operator==(const Range& lhs, const Range& rhs) = default;
friend size_t hash_value(const Range& range)
{
diff --git a/src/ranges.hh b/src/ranges.hh
index bf55ca09..7b568cd2 100644
--- a/src/ranges.hh
+++ b/src/ranges.hh
@@ -510,11 +510,7 @@ struct ConcatView
Iterator& operator++() { if (is2()) ++m_it2; else ++m_it1; return *this; }
Iterator operator++(int) { auto copy = *this; ++*this; return copy; }
- friend bool operator==(const Iterator& lhs, const Iterator& rhs)
- {
- return lhs.m_it1 == rhs.m_it1 and lhs.m_end1 == rhs.m_end1 and
- lhs.m_it2 == rhs.m_it2;
- }
+ friend bool operator==(const Iterator& lhs, const Iterator& rhs) = default;
private:
bool is2() const { return m_it1 == m_end1; }
diff --git a/src/regex.hh b/src/regex.hh
index 97ba8ebd..a4d3d769 100644
--- a/src/regex.hh
+++ b/src/regex.hh
@@ -60,7 +60,7 @@ struct MatchResults
iterator& operator++() { m_it += 2; return *this; }
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:
It m_it;
@@ -83,10 +83,7 @@ struct MatchResults
SubMatch{m_values[i*2], m_values[i*2+1]} : SubMatch{};
}
- friend bool operator==(const MatchResults& lhs, const MatchResults& rhs)
- {
- return lhs.m_values == rhs.m_values;
- }
+ friend bool operator==(const MatchResults& lhs, const MatchResults& rhs) = default;
void swap(MatchResults& other)
{
diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc
index 2b3ce073..b639884f 100644
--- a/src/terminal_ui.cc
+++ b/src/terminal_ui.cc
@@ -68,7 +68,7 @@ struct TerminalUI::Window::Line
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); }
};