Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MEMPTR<T> a little more T*-like #1385

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/Common/MemPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,36 @@ class MEMPTR : MEMPTRBase
return MEMPTR<X>(this->m_value);
}

MEMPTR operator+(const MEMPTR& ptr) noexcept
sint32 operator-(const MEMPTR& ptr) noexcept
requires(!std::is_void_v<T>)
{
return MEMPTR(this->GetMPTR() + ptr.GetMPTR());
}
MEMPTR operator-(const MEMPTR& ptr) noexcept
{
return MEMPTR(this->GetMPTR() - ptr.GetMPTR());
return static_cast<sint32>(this->GetMPTR() - ptr.GetMPTR());
}

MEMPTR operator+(sint32 v) noexcept
requires(!std::is_void_v<T>)
{
// 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<T>)
{
// 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<T>)
{
m_value += v * sizeof(T);
return *this;
}

template<typename Q = T>
std::enable_if_t<!std::is_same_v<Q, void>, Q>& operator*() const noexcept
requires(!std::is_void_v<Q>)
Q& operator*() const noexcept
{
return *GetPtr();
}
Expand All @@ -137,7 +138,8 @@ class MEMPTR : MEMPTRBase
}

template<typename Q = T>
std::enable_if_t<!std::is_same_v<Q, void>, Q>& operator[](int index) noexcept
requires(!std::is_void_v<Q>)
Q& operator[](int index) noexcept
{
return GetPtr()[index];
}
Expand Down
Loading