diff options
Diffstat (limited to 'include/fud_vector.hpp')
-rw-r--r-- | include/fud_vector.hpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp index 2b5de9a..52876fd 100644 --- a/include/fud_vector.hpp +++ b/include/fud_vector.hpp @@ -70,6 +70,12 @@ class Vector { rhs.m_capacity = 0; } + static constexpr Vector<T> NullVector() noexcept { + Vector<T> output{}; + output.m_allocator = &globalNullAllocator; + return output; + } + static Result<Vector<T>, FudStatus> withCapacity(size_t capacity, Allocator* allocator = &globalFudAllocator) { Vector<T> output{}; @@ -104,7 +110,7 @@ class Vector { } output.m_allocator = allocator; - output.m_data = static_cast<T*>(dataPtrResult.getOkay()); + output.m_data = reinterpret_cast<T*>(dataPtrResult.getOkay()); output.m_length = 0; output.m_capacity = capacity; return FudStatus::Success; @@ -341,7 +347,7 @@ class Vector { return dataPtrResult.takeError(); } - auto* dataPtr = static_cast<T*>(dataPtrResult.takeOkay()); + 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])); fudAssert(ptr != nullptr); @@ -350,7 +356,7 @@ class Vector { auto status = FudStatus::Success; if (m_capacity > 0) { - status = m_allocator->deallocate(m_data, m_capacity); + status = m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_capacity); } m_data = dataPtr; @@ -666,7 +672,7 @@ class Vector { auto status = clear(); if (m_data != nullptr && m_allocator != nullptr) { - auto deallocStatus = m_allocator->deallocate(m_data, m_capacity); + auto deallocStatus = m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_capacity); if (status == FudStatus::Success) { status = deallocStatus; } |