summaryrefslogtreecommitdiff
path: root/include/fud_vector.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-30 09:51:54 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-30 09:51:54 -0500
commit6c7fd1db481ff10a16ecab958c6542784fa60b9c (patch)
treee0162f930ec44a7c53b07061311d52910c36e481 /include/fud_vector.hpp
parent8dcb1de91e15ff7fc66279cd9cd9ad8a70f624e0 (diff)
Use std::byte* instead of void* for allocators.
Diffstat (limited to 'include/fud_vector.hpp')
-rw-r--r--include/fud_vector.hpp14
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;
}