refactor: Prefer <=> over multiple relational operators
Define `operator<=>` in classes that have all of `<`, `<=`, `>`, `>=`.
This commit is contained in:
4 files changed
+7
-28
No files matched your search
+2
-8
@@ -72,10 +72,7 @@ public:
|
|||||||
iterator operator-(size_type n) const { return iterator(ptr - n); }
|
iterator operator-(size_type n) const { return iterator(ptr - n); }
|
||||||
iterator& operator-=(size_type n) { ptr -= n; return *this; }
|
iterator& operator-=(size_type n) { ptr -= n; return *this; }
|
||||||
bool operator==(iterator x) const { return ptr == x.ptr; }
|
bool operator==(iterator x) const { return ptr == x.ptr; }
|
||||||
bool operator>=(iterator x) const { return ptr >= x.ptr; }
|
auto operator<=>(iterator x) const { return ptr <=> x.ptr; }
|
||||||
bool operator<=(iterator x) const { return ptr <= x.ptr; }
|
|
||||||
bool operator>(iterator x) const { return ptr > x.ptr; }
|
|
||||||
bool operator<(iterator x) const { return ptr < x.ptr; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class const_iterator {
|
class const_iterator {
|
||||||
@@ -103,10 +100,7 @@ public:
|
|||||||
const_iterator operator-(size_type n) const { return const_iterator(ptr - n); }
|
const_iterator operator-(size_type n) const { return const_iterator(ptr - n); }
|
||||||
const_iterator& operator-=(size_type n) { ptr -= n; return *this; }
|
const_iterator& operator-=(size_type n) { ptr -= n; return *this; }
|
||||||
bool operator==(const_iterator x) const { return ptr == x.ptr; }
|
bool operator==(const_iterator x) const { return ptr == x.ptr; }
|
||||||
bool operator>=(const_iterator x) const { return ptr >= x.ptr; }
|
auto operator<=>(const_iterator x) const { return ptr <=> x.ptr; }
|
||||||
bool operator<=(const_iterator x) const { return ptr <= x.ptr; }
|
|
||||||
bool operator>(const_iterator x) const { return ptr > x.ptr; }
|
|
||||||
bool operator<(const_iterator x) const { return ptr < x.ptr; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+2
-8
@@ -270,16 +270,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
|
inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
|
||||||
inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; }
|
inline auto operator<=>(const int64_t& rhs) const { return m_value <=> rhs; }
|
||||||
inline bool operator< (const int64_t& rhs) const { return m_value < rhs; }
|
|
||||||
inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; }
|
|
||||||
inline bool operator> (const int64_t& rhs) const { return m_value > rhs; }
|
|
||||||
|
|
||||||
inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
|
inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
|
||||||
inline bool operator<=(const CScriptNum& rhs) const { return operator<=(rhs.m_value); }
|
inline auto operator<=>(const CScriptNum& rhs) const { return operator<=>(rhs.m_value); }
|
||||||
inline bool operator< (const CScriptNum& rhs) const { return operator< (rhs.m_value); }
|
|
||||||
inline bool operator>=(const CScriptNum& rhs) const { return operator>=(rhs.m_value); }
|
|
||||||
inline bool operator> (const CScriptNum& rhs) const { return operator> (rhs.m_value); }
|
|
||||||
|
|
||||||
inline CScriptNum operator+( const int64_t& rhs) const { return CScriptNum(m_value + rhs);}
|
inline CScriptNum operator+( const int64_t& rhs) const { return CScriptNum(m_value + rhs);}
|
||||||
inline CScriptNum operator-( const int64_t& rhs) const { return CScriptNum(m_value - rhs);}
|
inline CScriptNum operator-( const int64_t& rhs) const { return CScriptNum(m_value - rhs);}
|
||||||
|
|||||||
@@ -61,16 +61,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
|
inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
|
||||||
inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; }
|
inline auto operator<=>(const int64_t& rhs) const { return m_value <=> rhs; }
|
||||||
inline bool operator< (const int64_t& rhs) const { return m_value < rhs; }
|
|
||||||
inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; }
|
|
||||||
inline bool operator> (const int64_t& rhs) const { return m_value > rhs; }
|
|
||||||
|
|
||||||
inline bool operator==(const CScriptNum10& rhs) const { return operator==(rhs.m_value); }
|
inline bool operator==(const CScriptNum10& rhs) const { return operator==(rhs.m_value); }
|
||||||
inline bool operator<=(const CScriptNum10& rhs) const { return operator<=(rhs.m_value); }
|
inline auto operator<=>(const CScriptNum10& rhs) const { return operator<=>(rhs.m_value); }
|
||||||
inline bool operator< (const CScriptNum10& rhs) const { return operator< (rhs.m_value); }
|
|
||||||
inline bool operator>=(const CScriptNum10& rhs) const { return operator>=(rhs.m_value); }
|
|
||||||
inline bool operator> (const CScriptNum10& rhs) const { return operator> (rhs.m_value); }
|
|
||||||
|
|
||||||
inline CScriptNum10 operator+( const int64_t& rhs) const { return CScriptNum10(m_value + rhs);}
|
inline CScriptNum10 operator+( const int64_t& rhs) const { return CScriptNum10(m_value + rhs);}
|
||||||
inline CScriptNum10 operator-( const int64_t& rhs) const { return CScriptNum10(m_value - rhs);}
|
inline CScriptNum10 operator-( const int64_t& rhs) const { return CScriptNum10(m_value - rhs);}
|
||||||
|
|||||||
+1
-4
@@ -99,10 +99,7 @@ class bitdeque
|
|||||||
friend Iterator operator+(Iterator x, difference_type dist) { x += dist; return x; }
|
friend Iterator operator+(Iterator x, difference_type dist) { x += dist; return x; }
|
||||||
friend Iterator operator+(difference_type dist, Iterator x) { x += dist; return x; }
|
friend Iterator operator+(difference_type dist, Iterator x) { x += dist; return x; }
|
||||||
friend Iterator operator-(Iterator x, difference_type dist) { x -= dist; return x; }
|
friend Iterator operator-(Iterator x, difference_type dist) { x -= dist; return x; }
|
||||||
friend bool operator<(const Iterator& x, const Iterator& y) { return std::tie(x.m_it, x.m_bitpos) < std::tie(y.m_it, y.m_bitpos); }
|
friend auto operator<=>(const Iterator& x, const Iterator& y) { return std::tie(x.m_it, x.m_bitpos) <=> std::tie(y.m_it, y.m_bitpos); }
|
||||||
friend bool operator>(const Iterator& x, const Iterator& y) { return std::tie(x.m_it, x.m_bitpos) > std::tie(y.m_it, y.m_bitpos); }
|
|
||||||
friend bool operator<=(const Iterator& x, const Iterator& y) { return std::tie(x.m_it, x.m_bitpos) <= std::tie(y.m_it, y.m_bitpos); }
|
|
||||||
friend bool operator>=(const Iterator& x, const Iterator& y) { return std::tie(x.m_it, x.m_bitpos) >= std::tie(y.m_it, y.m_bitpos); }
|
|
||||||
friend bool operator==(const Iterator& x, const Iterator& y) { return x.m_it == y.m_it && x.m_bitpos == y.m_bitpos; }
|
friend bool operator==(const Iterator& x, const Iterator& y) { return x.m_it == y.m_it && x.m_bitpos == y.m_bitpos; }
|
||||||
reference operator*() const { return (*m_it)[m_bitpos]; }
|
reference operator*() const { return (*m_it)[m_bitpos]; }
|
||||||
reference operator[](difference_type pos) const { return *(*this + pos); }
|
reference operator[](difference_type pos) const { return *(*this + pos); }
|
||||||
|
|||||||
Reference in new issue
Block a user