Codechange: Make OverflowSafeInt ConvertibleThroughBase. (#13449)

This commit is contained in:
Peter Nelson 2025-02-03 12:53:45 +00:00 committed by GitHub
parent 5f4f78574f
commit 64724b8893
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 8 deletions

View File

@ -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<T> max() { return T_MAX; }
static inline constexpr OverflowSafeInt<T> min() { return T_MIN; }
BaseType base() const noexcept { return this->m_value; }
};

View File

@ -12,8 +12,6 @@
#include <string_view>
#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<uint8_t>(data ? 1 : 0); }
template <typename T>
EndianBufferWriter &operator <<(const OverflowSafeInt<T> &data) { return *this << static_cast<T>(data); };
template <typename... Targs>
EndianBufferWriter &operator <<(const std::tuple<Targs...> &data)
{
@ -133,9 +128,6 @@ public:
EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; }
EndianBufferReader &operator >>(bool &data) { data = this->Read<uint8_t>() != 0; return *this; }
template <typename T>
EndianBufferReader &operator >>(OverflowSafeInt<T> &data) { data = this->Read<T>(); return *this; };
template <typename... Targs>
EndianBufferReader &operator >>(std::tuple<Targs...> &data)
{