Skip to content

Commit a4fc1b8

Browse files
Use C++20's operator<=> for implementing comparison operators rather than manually specifying them all
Signed-off-by: Christian Parpart <[email protected]>
1 parent 74059da commit a4fc1b8

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

include/boxed-cpp/boxed.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct boxed
7979
else
8080
return boxed<T, Tag>(static_cast<T>(value));
8181
}
82+
83+
[[nodiscard]] constexpr auto operator<=>(boxed const& other) const noexcept = default;
8284
};
8385

8486
template <typename T, typename U>
@@ -94,12 +96,6 @@ template <typename T, typename U> constexpr boxed<T, U>& operator--(boxed<T, U>&
9496
template <typename T, typename U> constexpr boxed<T, U> operator++(boxed<T, U>& a, int) noexcept { auto old = a; a.value++; return old; }
9597
template <typename T, typename U> constexpr boxed<T, U> operator--(boxed<T, U>& a, int) noexcept { auto old = a; a.value--; return old; }
9698
template <typename T, typename U> constexpr T const& operator*(boxed<T, U> const& a) noexcept { return a.value; }
97-
template <typename T, typename U> constexpr bool operator<(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return a.value < b.value; }
98-
template <typename T, typename U> constexpr bool operator>(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return a.value > b.value; }
99-
template <typename T, typename U> constexpr bool operator<=(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return a.value <= b.value; }
100-
template <typename T, typename U> constexpr bool operator>=(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return a.value >= b.value; }
101-
template <typename T, typename U> constexpr bool operator==(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return a.value == b.value; }
102-
template <typename T, typename U> constexpr bool operator!=(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return a.value != b.value; }
10399
template <typename T, typename U> constexpr bool operator!(boxed<T, U> const& a) noexcept { return !a.value; }
104100
template <typename T, typename U> constexpr boxed<T, U> operator+(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return boxed<T, U>{a.value + b.value}; }
105101
template <typename T, typename U> constexpr boxed<T, U> operator-(boxed<T, U> const& a, boxed<T, U> const& b) noexcept { return boxed<T, U>{a.value - b.value}; }

0 commit comments

Comments
 (0)