Skip to content

Commit 47001ad

Browse files
Make MEMPTR<T> a little more T*-like (#1385)
1 parent 459fd5d commit 47001ad

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/Common/MemPtr.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -98,35 +98,36 @@ class MEMPTR : MEMPTRBase
9898
return MEMPTR<X>(this->m_value);
9999
}
100100

101-
MEMPTR operator+(const MEMPTR& ptr) noexcept
101+
sint32 operator-(const MEMPTR& ptr) noexcept
102+
requires(!std::is_void_v<T>)
102103
{
103-
return MEMPTR(this->GetMPTR() + ptr.GetMPTR());
104-
}
105-
MEMPTR operator-(const MEMPTR& ptr) noexcept
106-
{
107-
return MEMPTR(this->GetMPTR() - ptr.GetMPTR());
104+
return static_cast<sint32>(this->GetMPTR() - ptr.GetMPTR());
108105
}
109106

110107
MEMPTR operator+(sint32 v) noexcept
108+
requires(!std::is_void_v<T>)
111109
{
112110
// pointer arithmetic
113-
return MEMPTR(this->GetMPTR() + v * 4);
111+
return MEMPTR(this->GetMPTR() + v * sizeof(T));
114112
}
115113

116114
MEMPTR operator-(sint32 v) noexcept
115+
requires(!std::is_void_v<T>)
117116
{
118117
// pointer arithmetic
119-
return MEMPTR(this->GetMPTR() - v * 4);
118+
return MEMPTR(this->GetMPTR() - v * sizeof(T));
120119
}
121120

122121
MEMPTR& operator+=(sint32 v) noexcept
122+
requires(!std::is_void_v<T>)
123123
{
124124
m_value += v * sizeof(T);
125125
return *this;
126126
}
127127

128128
template<typename Q = T>
129-
std::enable_if_t<!std::is_same_v<Q, void>, Q>& operator*() const noexcept
129+
requires(!std::is_void_v<Q>)
130+
Q& operator*() const noexcept
130131
{
131132
return *GetPtr();
132133
}
@@ -137,7 +138,8 @@ class MEMPTR : MEMPTRBase
137138
}
138139

139140
template<typename Q = T>
140-
std::enable_if_t<!std::is_same_v<Q, void>, Q>& operator[](int index) noexcept
141+
requires(!std::is_void_v<Q>)
142+
Q& operator[](int index) noexcept
141143
{
142144
return GetPtr()[index];
143145
}

0 commit comments

Comments
 (0)