diff options
Diffstat (limited to 'include/fud_vector.hpp')
-rw-r--r-- | include/fud_vector.hpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp index 9159770..1730c50 100644 --- a/include/fud_vector.hpp +++ b/include/fud_vector.hpp @@ -59,16 +59,21 @@ class Vector { Vector& operator=(Vector<T>&& rhs) noexcept { - cleanup(); + if (&rhs == this) { + return *this; + } + static_cast<void>(cleanup()); m_allocator = rhs.m_allocator; m_data = rhs.m_data; m_length = rhs.m_length; m_capacity = rhs.m_length; - rhs.m_allocataor = nullptr; + rhs.m_allocator = nullptr; rhs.m_data = nullptr; rhs.m_length = 0; rhs.m_capacity = 0; + + return *this; } static constexpr Vector<T> NullVector() noexcept { @@ -629,6 +634,32 @@ class Vector { return FudStatus::Success; } + template <size_t Size> + FudStatus extend(Span<const T, Size> fixedSpan) + { + if (fixedSpan.data() == nullptr) { + return FudStatus::NullPointer; + } + if (std::numeric_limits<size_t>::max() - Size < m_length) { + return FudStatus::Failure; + } + if (m_length + Size > m_capacity) + { + auto status = grow(); + if (status != FudStatus::Success) { + return status; + } + } + + for (size_t spanIndex = 0; spanIndex < Size; ++spanIndex) { + const auto* ptr = new (m_data + m_length) T(fixedSpan[spanIndex]); + fudAssert(ptr != nullptr); + m_length++; + } + + return FudStatus::Success; + } + FudStatus erase(size_t index) { if (index >= m_length) { |