diff --git a/include/Nazara/Core/SparsePtr.hpp b/include/Nazara/Core/SparsePtr.hpp index aff3460ac..94c3f249f 100644 --- a/include/Nazara/Core/SparsePtr.hpp +++ b/include/Nazara/Core/SparsePtr.hpp @@ -22,6 +22,7 @@ class NzSparsePtr NzSparsePtr(); NzSparsePtr(T* ptr); NzSparsePtr(VoidPtr ptr, unsigned int stride); + template NzSparsePtr(const NzSparsePtr& ptr); NzSparsePtr(const NzSparsePtr& ptr) = default; ~NzSparsePtr() = default; @@ -32,6 +33,7 @@ class NzSparsePtr void Reset(T* ptr); void Reset(VoidPtr ptr, unsigned int stride); void Reset(const NzSparsePtr& ptr); + template void Reset(const NzSparsePtr& ptr); void SetPtr(VoidPtr ptr); void SetStride(unsigned int stride); diff --git a/include/Nazara/Core/SparsePtr.inl b/include/Nazara/Core/SparsePtr.inl index b98599bfd..ca0d7e328 100644 --- a/include/Nazara/Core/SparsePtr.inl +++ b/include/Nazara/Core/SparsePtr.inl @@ -22,6 +22,13 @@ NzSparsePtr::NzSparsePtr(VoidPtr ptr, unsigned int stride) Reset(ptr, stride); } +template +template +NzSparsePtr::NzSparsePtr(const NzSparsePtr& ptr) +{ + Reset(ptr); +} + template typename NzSparsePtr::VoidPtr NzSparsePtr::GetPtr() const { @@ -62,6 +69,16 @@ void NzSparsePtr::Reset(const NzSparsePtr& ptr) SetStride(ptr.GetStride()); } +template +template +void NzSparsePtr::Reset(const NzSparsePtr& ptr) +{ + static_assert(std::is_convertible::value, "Source type pointer cannot be implicitely converted to target type pointer"); + + SetPtr(static_cast(ptr.GetPtr())); + SetStride(ptr.GetStride()); +} + template void NzSparsePtr::SetPtr(VoidPtr ptr) { @@ -120,6 +137,7 @@ template NzSparsePtr& NzSparsePtr::operator+=(unsigned int count) { m_ptr += count*m_stride; + return *this; } @@ -127,6 +145,7 @@ template NzSparsePtr& NzSparsePtr::operator-=(unsigned int count) { m_ptr -= count*m_stride; + return *this; } @@ -134,6 +153,7 @@ template NzSparsePtr& NzSparsePtr::operator++() { m_ptr += m_stride; + return *this; }