From 6c7fd1db481ff10a16ecab958c6542784fa60b9c Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 30 Oct 2024 09:51:54 -0500 Subject: Use std::byte* instead of void* for allocators. --- include/fud_vector.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'include/fud_vector.hpp') 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 NullVector() noexcept { + Vector output{}; + output.m_allocator = &globalNullAllocator; + return output; + } + static Result, FudStatus> withCapacity(size_t capacity, Allocator* allocator = &globalFudAllocator) { Vector output{}; @@ -104,7 +110,7 @@ class Vector { } output.m_allocator = allocator; - output.m_data = static_cast(dataPtrResult.getOkay()); + output.m_data = reinterpret_cast(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(dataPtrResult.takeOkay()); + auto* dataPtr = reinterpret_cast(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(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(m_data), m_capacity); if (status == FudStatus::Success) { status = deallocStatus; } -- cgit v1.2.3