Added implicit conversion to SparsePtr
Former-commit-id: 5116a5e7687706640cd5d2ef99f5c181e00ee841
This commit is contained in:
parent
a51cbc1e49
commit
15ddc29179
|
|
@ -22,6 +22,7 @@ class NzSparsePtr
|
|||
NzSparsePtr();
|
||||
NzSparsePtr(T* ptr);
|
||||
NzSparsePtr(VoidPtr ptr, unsigned int stride);
|
||||
template<typename U> NzSparsePtr(const NzSparsePtr<U>& 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<typename U> void Reset(const NzSparsePtr<U>& ptr);
|
||||
|
||||
void SetPtr(VoidPtr ptr);
|
||||
void SetStride(unsigned int stride);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ NzSparsePtr<T>::NzSparsePtr(VoidPtr ptr, unsigned int stride)
|
|||
Reset(ptr, stride);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
NzSparsePtr<T>::NzSparsePtr(const NzSparsePtr<U>& ptr)
|
||||
{
|
||||
Reset(ptr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename NzSparsePtr<T>::VoidPtr NzSparsePtr<T>::GetPtr() const
|
||||
{
|
||||
|
|
@ -62,6 +69,16 @@ void NzSparsePtr<T>::Reset(const NzSparsePtr& ptr)
|
|||
SetStride(ptr.GetStride());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
void NzSparsePtr<T>::Reset(const NzSparsePtr<U>& ptr)
|
||||
{
|
||||
static_assert(std::is_convertible<U*, T*>::value, "Source type pointer cannot be implicitely converted to target type pointer");
|
||||
|
||||
SetPtr(static_cast<T*>(ptr.GetPtr()));
|
||||
SetStride(ptr.GetStride());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzSparsePtr<T>::SetPtr(VoidPtr ptr)
|
||||
{
|
||||
|
|
@ -120,6 +137,7 @@ template<typename T>
|
|||
NzSparsePtr<T>& NzSparsePtr<T>::operator+=(unsigned int count)
|
||||
{
|
||||
m_ptr += count*m_stride;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -127,6 +145,7 @@ template<typename T>
|
|||
NzSparsePtr<T>& NzSparsePtr<T>::operator-=(unsigned int count)
|
||||
{
|
||||
m_ptr -= count*m_stride;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -134,6 +153,7 @@ template<typename T>
|
|||
NzSparsePtr<T>& NzSparsePtr<T>::operator++()
|
||||
{
|
||||
m_ptr += m_stride;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue