1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-24 07:53:41 +03:00

Convert comparisons to spaceship operator

This commit is contained in:
Maxime Coste 2020-11-15 08:57:19 +11:00
parent fb4cef5b61
commit ab9d78f50d
6 changed files with 11 additions and 104 deletions

View File

@ -68,14 +68,8 @@ public:
BufferIterator(const Buffer& buffer, BufferCoord coord) noexcept; 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; std::strong_ordering 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 BufferCoord& coord) const noexcept; bool operator== (const BufferCoord& coord) const noexcept;
bool operator!= (const BufferCoord& coord) const noexcept;
const char& operator* () const noexcept; const char& operator* () const noexcept;
const char& operator[](size_t n) const noexcept; const char& operator[](size_t n) const noexcept;

View File

@ -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; return m_buffer == iterator.m_buffer and 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
{
return m_buffer != iterator.m_buffer or m_coord != iterator.m_coord;
}
inline bool BufferIterator::operator<(const BufferIterator& iterator) const noexcept
{ {
kak_assert(m_buffer == iterator.m_buffer); kak_assert(m_buffer == iterator.m_buffer);
return (m_coord < iterator.m_coord); 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);
} }
inline bool BufferIterator::operator==(const BufferCoord& coord) const noexcept 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; return m_coord == coord;
} }
inline bool BufferIterator::operator!=(const BufferCoord& coord) const noexcept
{
return m_coord != coord;
}
[[gnu::always_inline]] [[gnu::always_inline]]
inline const char& BufferIterator::operator*() const noexcept inline const char& BufferIterator::operator*() const noexcept
{ {

View File

@ -42,31 +42,10 @@ struct LineAndColumn
} }
[[gnu::always_inline]] [[gnu::always_inline]]
constexpr bool operator< (EffectiveType other) const constexpr auto operator<=> (EffectiveType other) const
{ {
return (line != other.line) ? line < other.line return (line != other.line) ? line <=> other.line
: column < other.column; : 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;
} }
[[gnu::always_inline]] [[gnu::always_inline]]
@ -75,12 +54,6 @@ struct LineAndColumn
return line == other.line and column == other.column; 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) friend constexpr size_t hash_value(const EffectiveType& val)
{ {
return hash_values(val.line, val.column); return hash_values(val.line, val.column);

View File

@ -84,7 +84,6 @@ struct Key
constexpr uint64_t val() const { return (uint64_t)modifiers << 32 | 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 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)}; } constexpr DisplayCoord coord() const { return {(int)((key & 0xFFFF0000) >> 16), (int)(key & 0x0000FFFF)}; }

View File

@ -83,28 +83,12 @@ public:
{ m_value %= other.m_value; return static_cast<RealType&>(*this); } { m_value %= other.m_value; return static_cast<RealType&>(*this); }
[[gnu::always_inline]] [[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; } { return lhs.m_value == rhs.m_value; }
[[gnu::always_inline]] [[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; } { 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]] [[gnu::always_inline]]
constexpr bool operator!() const constexpr bool operator!() const

View File

@ -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; } auto 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; }
template<typename T> template<typename T>
requires std::is_same_v<T, BaseIt> or std::is_same_v<T, Sentinel> requires std::is_same_v<T, BaseIt> or std::is_same_v<T, Sentinel>
bool operator==(const T& other) const noexcept { return m_it == other; } bool operator==(const T& other) const noexcept { return m_it == other; }
auto operator<=> (const BaseIt& other) const noexcept { return m_it <=> other; }
template<typename T>
requires std::is_same_v<T, BaseIt> or std::is_same_v<T, Sentinel>
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; }
DifferenceType operator-(const iterator& other) const noexcept(noexcept_policy) DifferenceType operator-(const iterator& other) const noexcept(noexcept_policy)
{ {