diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2025-01-02 18:49:56 -0600 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2025-01-02 18:49:56 -0600 |
commit | d5a174a6d4f8be5e7cffe7c2adbb8db23b578f56 (patch) | |
tree | 536a10802f418e3e71f3828597439537d9e62f21 /include/fud_vector.hpp | |
parent | 908fdf06b41f9084d719a4b517c868b1ad29a9ac (diff) |
Fixing errors in Vector.
Diffstat (limited to 'include/fud_vector.hpp')
-rw-r--r-- | include/fud_vector.hpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp index 2942e71..760587b 100644 --- a/include/fud_vector.hpp +++ b/include/fud_vector.hpp @@ -116,6 +116,7 @@ class Vector { } output.m_allocator = allocator; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) output.m_data = reinterpret_cast<T*>(dataPtrResult.getOkay()); output.m_length = 0; output.m_capacity = capacity; @@ -354,6 +355,7 @@ class Vector { return dataPtrResult.takeError(); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto* dataPtr = reinterpret_cast<T*>(dataPtrResult.takeOkay()); for (size_t index = 0; index < m_length; ++index) { const auto* ptr = new (dataPtr + index) T(std::move(m_data[index])); @@ -363,6 +365,7 @@ class Vector { auto status = FudStatus::Success; if (m_capacity > 0) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_capacity); } @@ -645,7 +648,9 @@ class Vector { } if (m_length + Size > m_capacity) { - auto status = grow(); + size_t currentLength = m_length; + auto status = resize(m_length + Size); + m_length = currentLength; if (status != FudStatus::Success) { return status; } @@ -660,6 +665,33 @@ class Vector { return FudStatus::Success; } + FudStatus extend(Span<const T> span) + { + if (span.data() == nullptr) { + return FudStatus::NullPointer; + } + if (std::numeric_limits<size_t>::max() - span.size() < m_length) { + return FudStatus::Failure; + } + if (m_length + span.size() > m_capacity) + { + size_t currentLength = m_length; + auto status = resize(m_length + span.size()); + m_length = currentLength; + if (status != FudStatus::Success) { + return status; + } + } + + for (size_t spanIndex = 0; spanIndex < span.size(); ++spanIndex) { + const auto* ptr = new (m_data + m_length) T(span[spanIndex]); + fudAssert(ptr != nullptr); + m_length++; + } + + return FudStatus::Success; + } + FudStatus erase(size_t index) { if (index >= m_length) { @@ -709,6 +741,7 @@ class Vector { auto status = clear(); if (m_data != nullptr && m_allocator != nullptr) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_capacity); } |