refactor: Prefer `<=>` over multiple relational operators
What changed, and why it matters
This commit is a routine code cleanup that replaces several older-style comparison operators with C++20's newer three-way comparison operator (<=>). It does not change what the code does, only how it is written. There is no security issue here.
No security action required. Treat as normal code-quality refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors four header files to use operator<=> instead of manually defining operator<, operator<=, operator>, and operator>=. The affected classes are prevector::iterator/const_iterator, CScriptNum, CScriptNum10, and bitdeque::Iterator. The generated comparison semantics remain equivalent because the new operator delegates to the same underlying comparisons (ptr <=> ptr, m_value <=> rhs, and std::tie(...) <=> std::tie(...)). This is a pure modernization/refactoring change.
Changed components
src/prevector.hsrc/script/script.hsrc/test/scriptnum10.hsrc/util/bitdeque.hInspect captured patch +7 / −28
diff --git a/src/prevector.h b/src/prevector.h
index 2c794d71..d4d90c73 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -72,10 +72,7 @@ public:
iterator operator-(size_type n) const { return iterator(ptr - n); }
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; }
- 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; }
};
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) { 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; }
- 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; }
};
private:
diff --git a/src/script/script.h b/src/script/script.h
index 633b5609..b06be9c9 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -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 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 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 bool operator> (const CScriptNum& rhs) const { return operator> (rhs.m_value); }
+ inline auto 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);}
diff --git a/src/test/scriptnum10.h b/src/test/scriptnum10.h
index bf708aac..40260671 100644
--- a/src/test/scriptnum10.h
+++ b/src/test/scriptnum10.h
@@ -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 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 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 bool operator> (const CScriptNum10& rhs) const { return operator> (rhs.m_value); }
+ inline auto 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);}
diff --git a/src/util/bitdeque.h b/src/util/bitdeque.h
index 2d21c8b3..21934e02 100644
--- a/src/util/bitdeque.h
+++ b/src/util/bitdeque.h
@@ -99,10 +99,7 @@ class bitdeque
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-(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 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 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 x.m_it == y.m_it && x.m_bitpos == y.m_bitpos; }
reference operator*() const { return (*m_it)[m_bitpos]; }
reference operator[](difference_type pos) const { return *(*this + pos); }
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.