From 47001ad23349fae130d6faae9409117899eb11cc Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Wed, 30 Oct 2024 22:10:32 +0000 Subject: [PATCH] Make `MEMPTR` a little more `T*`-like (#1385) --- src/Common/MemPtr.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Common/MemPtr.h b/src/Common/MemPtr.h index 7825e4d5..2dc92040 100644 --- a/src/Common/MemPtr.h +++ b/src/Common/MemPtr.h @@ -98,35 +98,36 @@ class MEMPTR : MEMPTRBase return MEMPTR(this->m_value); } - MEMPTR operator+(const MEMPTR& ptr) noexcept + sint32 operator-(const MEMPTR& ptr) noexcept + requires(!std::is_void_v) { - return MEMPTR(this->GetMPTR() + ptr.GetMPTR()); - } - MEMPTR operator-(const MEMPTR& ptr) noexcept - { - return MEMPTR(this->GetMPTR() - ptr.GetMPTR()); + return static_cast(this->GetMPTR() - ptr.GetMPTR()); } MEMPTR operator+(sint32 v) noexcept + requires(!std::is_void_v) { // pointer arithmetic - return MEMPTR(this->GetMPTR() + v * 4); + return MEMPTR(this->GetMPTR() + v * sizeof(T)); } MEMPTR operator-(sint32 v) noexcept + requires(!std::is_void_v) { // pointer arithmetic - return MEMPTR(this->GetMPTR() - v * 4); + return MEMPTR(this->GetMPTR() - v * sizeof(T)); } MEMPTR& operator+=(sint32 v) noexcept + requires(!std::is_void_v) { m_value += v * sizeof(T); return *this; } template - std::enable_if_t, Q>& operator*() const noexcept + requires(!std::is_void_v) + Q& operator*() const noexcept { return *GetPtr(); } @@ -137,7 +138,8 @@ class MEMPTR : MEMPTRBase } template - std::enable_if_t, Q>& operator[](int index) noexcept + requires(!std::is_void_v) + Q& operator[](int index) noexcept { return GetPtr()[index]; }