libluna: Allow constructing a Slice from another one with a different pointer type

This commit is contained in:
apio 2023-04-26 20:41:24 +02:00
parent cb28e2a385
commit 36bc217056
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -11,6 +11,10 @@ template <typename T> class Slice
{ {
} }
template <typename Tp> Slice(const Slice<Tp>& other) : m_data((T*)other.m_data), m_size(other.m_size)
{
}
const T* data() const const T* data() const
{ {
return m_data; return m_data;
@ -46,6 +50,18 @@ template <typename T> class Slice
return m_data + m_size; return m_data + m_size;
} }
const T& operator[](usize index) const
{
check(index < m_size);
return m_data[index];
}
T& operator[](usize index)
{
check(index < m_size);
return m_data[index];
}
private: private:
T* const m_data; T* const m_data;
const usize m_size; const usize m_size;