Skip to content

Commit 46ff422

Browse files
committed
arith_uint256: modernize comparison operators
Since C++20, operator!= is implicitly defaulted using operator==, and operator<, operator<=, operator>, and operator>= are defaulted using operator<=>, so it suffices to just provide these two.
1 parent 0dc74c9 commit 46ff422

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/arith_uint256.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef BITCOIN_ARITH_UINT256_H
77
#define BITCOIN_ARITH_UINT256_H
88

9+
#include <compare>
910
#include <cstdint>
1011
#include <cstring>
1112
#include <limits>
@@ -212,13 +213,8 @@ class base_uint
212213
friend inline base_uint operator<<(const base_uint& a, int shift) { return base_uint(a) <<= shift; }
213214
friend inline base_uint operator*(const base_uint& a, uint32_t b) { return base_uint(a) *= b; }
214215
friend inline bool operator==(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) == 0; }
215-
friend inline bool operator!=(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) != 0; }
216-
friend inline bool operator>(const base_uint& a, const base_uint& b) { return a.CompareTo(b) > 0; }
217-
friend inline bool operator<(const base_uint& a, const base_uint& b) { return a.CompareTo(b) < 0; }
218-
friend inline bool operator>=(const base_uint& a, const base_uint& b) { return a.CompareTo(b) >= 0; }
219-
friend inline bool operator<=(const base_uint& a, const base_uint& b) { return a.CompareTo(b) <= 0; }
216+
friend inline std::strong_ordering operator<=>(const base_uint& a, const base_uint& b) { return a.CompareTo(b) <=> 0; }
220217
friend inline bool operator==(const base_uint& a, uint64_t b) { return a.EqualTo(b); }
221-
friend inline bool operator!=(const base_uint& a, uint64_t b) { return !a.EqualTo(b); }
222218

223219
/** Hex encoding of the number (with the most significant digits first). */
224220
std::string GetHex() const;

0 commit comments

Comments
 (0)