diff --git a/luna/include/luna/Vector.h b/luna/include/luna/Vector.h index d86e9e4b..46393feb 100644 --- a/luna/include/luna/Vector.h +++ b/luna/include/luna/Vector.h @@ -14,6 +14,60 @@ template class Vector { } + Vector(const Vector& other) + { + reserve(other.capacity()); + memcpy(m_data, other.data(), other.size()); + m_size = other.size(); + } + + Vector(Vector&& other) + { + m_data = other.data(); + m_capacity = other.capacity(); + m_size = other.size(); + + other.m_capacity = other.m_size = 0; + other.m_data = nullptr; + } + + Vector& operator=(const Vector& other) + { + if (&other == this) return *this; + + if (m_data) free_impl(m_data); + + m_data = nullptr; + m_capacity = m_size = 0; + + reserve(other.capacity()); + memcpy(m_data, other.data(), other.size()); + m_size = other.size(); + + return *this; + } + + Vector& operator=(Vector&& other) + { + if (&other == this) return *this; + + if (m_data) free_impl(m_data); + + m_data = other.data(); + m_capacity = other.capacity(); + m_size = other.size(); + + other.m_capacity = other.m_size = 0; + other.m_data = nullptr; + + return *this; + } + + ~Vector() + { + if (m_data) free_impl(m_data); + } + Result try_reserve(usize capacity) { return resize(capacity);