From ab9d78f50ddba621f875cf5ceb9da3e20d0a04f5 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 15 Nov 2020 08:57:19 +1100 Subject: [PATCH] Convert comparisons to spaceship operator --- src/buffer.hh | 8 +------- src/buffer.inl.hh | 32 ++------------------------------ src/coord.hh | 33 +++------------------------------ src/keys.hh | 1 - src/units.hh | 22 +++------------------- src/utf8_iterator.hh | 19 ++----------------- 6 files changed, 11 insertions(+), 104 deletions(-) diff --git a/src/buffer.hh b/src/buffer.hh index 4bd1409e5..7dd4bdad1 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -68,14 +68,8 @@ public: BufferIterator(const Buffer& buffer, BufferCoord coord) noexcept; bool operator== (const BufferIterator& iterator) const noexcept; - bool operator!= (const BufferIterator& iterator) const noexcept; - bool operator< (const BufferIterator& iterator) const noexcept; - bool operator<= (const BufferIterator& iterator) const noexcept; - bool operator> (const BufferIterator& iterator) const noexcept; - bool operator>= (const BufferIterator& iterator) const noexcept; - + std::strong_ordering operator<=>(const BufferIterator& iterator) const noexcept; bool operator== (const BufferCoord& coord) const noexcept; - bool operator!= (const BufferCoord& coord) const noexcept; const char& operator* () const noexcept; const char& operator[](size_t n) const noexcept; diff --git a/src/buffer.inl.hh b/src/buffer.inl.hh index 3bc6a0b01..4f264c0de 100644 --- a/src/buffer.inl.hh +++ b/src/buffer.inl.hh @@ -107,33 +107,10 @@ inline bool BufferIterator::operator==(const BufferIterator& iterator) const noe return m_buffer == iterator.m_buffer and m_coord == iterator.m_coord; } -inline bool BufferIterator::operator!=(const BufferIterator& iterator) const noexcept -{ - return m_buffer != iterator.m_buffer or m_coord != iterator.m_coord; -} - -inline bool BufferIterator::operator<(const BufferIterator& iterator) const noexcept +inline std::strong_ordering BufferIterator::operator<=>(const BufferIterator& iterator) const noexcept { kak_assert(m_buffer == iterator.m_buffer); - return (m_coord < iterator.m_coord); -} - -inline bool BufferIterator::operator<=(const BufferIterator& iterator) const noexcept -{ - kak_assert(m_buffer == iterator.m_buffer); - return (m_coord <= iterator.m_coord); -} - -inline bool BufferIterator::operator>(const BufferIterator& iterator) const noexcept -{ - kak_assert(m_buffer == iterator.m_buffer); - return (m_coord > iterator.m_coord); -} - -inline bool BufferIterator::operator>=(const BufferIterator& iterator) const noexcept -{ - kak_assert(m_buffer == iterator.m_buffer); - return (m_coord >= iterator.m_coord); + return (m_coord <=> iterator.m_coord); } inline bool BufferIterator::operator==(const BufferCoord& coord) const noexcept @@ -141,11 +118,6 @@ inline bool BufferIterator::operator==(const BufferCoord& coord) const noexcept return m_coord == coord; } -inline bool BufferIterator::operator!=(const BufferCoord& coord) const noexcept -{ - return m_coord != coord; -} - [[gnu::always_inline]] inline const char& BufferIterator::operator*() const noexcept { diff --git a/src/coord.hh b/src/coord.hh index 6109bf14c..30f8e1c0b 100644 --- a/src/coord.hh +++ b/src/coord.hh @@ -42,31 +42,10 @@ struct LineAndColumn } [[gnu::always_inline]] - constexpr bool operator< (EffectiveType other) const + constexpr auto operator<=> (EffectiveType other) const { - return (line != other.line) ? line < other.line - : column < other.column; - } - - [[gnu::always_inline]] - constexpr bool operator<= (EffectiveType other) const - { - return (line != other.line) ? line < other.line - : column <= other.column; - } - - [[gnu::always_inline]] - constexpr bool operator> (EffectiveType other) const - { - return (line != other.line) ? line > other.line - : column > other.column; - } - - [[gnu::always_inline]] - constexpr bool operator>= (EffectiveType other) const - { - return (line != other.line) ? line > other.line - : column >= other.column; + return (line != other.line) ? line <=> other.line + : column <=> other.column; } [[gnu::always_inline]] @@ -75,12 +54,6 @@ struct LineAndColumn return line == other.line and column == other.column; } - [[gnu::always_inline]] - constexpr bool operator!= (EffectiveType other) const - { - return line != other.line or column != other.column; - } - friend constexpr size_t hash_value(const EffectiveType& val) { return hash_values(val.line, val.column); diff --git a/src/keys.hh b/src/keys.hh index 0f5fc0e74..f06a7e2f8 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -84,7 +84,6 @@ struct Key constexpr uint64_t val() const { return (uint64_t)modifiers << 32 | key; } constexpr bool operator==(Key other) const { return val() == other.val(); } - constexpr bool operator!=(Key other) const { return val() != other.val(); } constexpr bool operator<(Key other) const { return val() < other.val(); } constexpr DisplayCoord coord() const { return {(int)((key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; } diff --git a/src/units.hh b/src/units.hh index 1c10c3af9..c7c9b8e6c 100644 --- a/src/units.hh +++ b/src/units.hh @@ -83,28 +83,12 @@ public: { m_value %= other.m_value; return static_cast(*this); } [[gnu::always_inline]] - constexpr friend bool operator==(RealType lhs, RealType rhs) + constexpr friend auto operator==(RealType lhs, RealType rhs) { return lhs.m_value == rhs.m_value; } [[gnu::always_inline]] - constexpr friend bool operator!=(RealType lhs, RealType rhs) - { return lhs.m_value != rhs.m_value; } - - [[gnu::always_inline]] - constexpr friend bool operator<(RealType lhs, RealType rhs) - { return lhs.m_value < rhs.m_value; } - - [[gnu::always_inline]] - constexpr friend bool operator<=(RealType lhs, RealType rhs) - { return lhs.m_value <= rhs.m_value; } - - [[gnu::always_inline]] - constexpr friend bool operator>(RealType lhs, RealType rhs) - { return lhs.m_value > rhs.m_value; } - - [[gnu::always_inline]] - constexpr friend bool operator>=(RealType lhs, RealType rhs) - { return lhs.m_value >= rhs.m_value; } + constexpr friend auto operator<=>(RealType lhs, RealType rhs) + { return lhs.m_value <=> rhs.m_value; } [[gnu::always_inline]] constexpr bool operator!() const diff --git a/src/utf8_iterator.hh b/src/utf8_iterator.hh index 618a44a95..4fd34f542 100644 --- a/src/utf8_iterator.hh +++ b/src/utf8_iterator.hh @@ -100,27 +100,12 @@ public: } bool operator==(const iterator& other) const noexcept { return m_it == other.m_it; } - bool operator!=(const iterator& other) const noexcept { return m_it != other.m_it; } - - bool operator< (const iterator& other) const noexcept { return m_it < other.m_it; } - bool operator<= (const iterator& other) const noexcept { return m_it <= other.m_it; } - - bool operator> (const iterator& other) const noexcept { return m_it > other.m_it; } - bool operator>= (const iterator& other) const noexcept { return m_it >= other.m_it; } + auto operator<=> (const iterator& other) const noexcept { return m_it <=> other.m_it; } template requires std::is_same_v or std::is_same_v bool operator==(const T& other) const noexcept { return m_it == other; } - - template - requires std::is_same_v or std::is_same_v - bool operator!=(const T& other) const noexcept { return m_it != other; } - - bool operator< (const BaseIt& other) const noexcept { return m_it < other; } - bool operator<= (const BaseIt& other) const noexcept { return m_it <= other; } - - bool operator> (const BaseIt& other) const noexcept { return m_it > other; } - bool operator>= (const BaseIt& other) const noexcept { return m_it >= other; } + auto operator<=> (const BaseIt& other) const noexcept { return m_it <=> other; } DifferenceType operator-(const iterator& other) const noexcept(noexcept_policy) {