From 64724b8893aaac182bff5010ebc5e3fcb081a19f Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 3 Feb 2025 12:53:45 +0000 Subject: [PATCH] Codechange: Make OverflowSafeInt ConvertibleThroughBase. (#13449) --- src/core/overflowsafe_type.hpp | 4 ++++ src/misc/endian_buffer.hpp | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index 95fee34fa0..f742d4778c 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -35,6 +35,8 @@ private: /** The non-overflow safe backend to store the value in. */ T m_value; public: + using BaseType = T; + constexpr OverflowSafeInt() : m_value(0) { } constexpr OverflowSafeInt(const OverflowSafeInt &other) : m_value(other.m_value) { } @@ -178,6 +180,8 @@ public: static inline constexpr OverflowSafeInt max() { return T_MAX; } static inline constexpr OverflowSafeInt min() { return T_MIN; } + + BaseType base() const noexcept { return this->m_value; } }; diff --git a/src/misc/endian_buffer.hpp b/src/misc/endian_buffer.hpp index 7ba7e3366f..284b2c9364 100644 --- a/src/misc/endian_buffer.hpp +++ b/src/misc/endian_buffer.hpp @@ -12,8 +12,6 @@ #include #include "../core/bitmath_func.hpp" -#include "../core/enum_type.hpp" -#include "../core/overflowsafe_type.hpp" /** * Endian-aware buffer adapter that always writes values in little endian order. @@ -35,9 +33,6 @@ public: EndianBufferWriter &operator <<(std::string_view data) { this->Write(data); return *this; } EndianBufferWriter &operator <<(bool data) { return *this << static_cast(data ? 1 : 0); } - template - EndianBufferWriter &operator <<(const OverflowSafeInt &data) { return *this << static_cast(data); }; - template EndianBufferWriter &operator <<(const std::tuple &data) { @@ -133,9 +128,6 @@ public: EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; } EndianBufferReader &operator >>(bool &data) { data = this->Read() != 0; return *this; } - template - EndianBufferReader &operator >>(OverflowSafeInt &data) { data = this->Read(); return *this; }; - template EndianBufferReader &operator >>(std::tuple &data) {