From e8422002f84dc4313894a5b3136c44a9005081fd Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 2 Nov 2024 20:45:02 -0500 Subject: Allocator deallocate is void rather than returning FudStatus. --- include/fud_vector.hpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'include/fud_vector.hpp') diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp index 52876fd..53b2625 100644 --- a/include/fud_vector.hpp +++ b/include/fud_vector.hpp @@ -39,6 +39,7 @@ class Vector { public: constexpr Vector() noexcept = default; + constexpr explicit Vector(Allocator& allocator) noexcept : m_allocator{&allocator} {} constexpr Vector(const Vector& rhs) = delete; constexpr Vector(Vector&& rhs) noexcept : m_allocator(rhs.m_allocator), m_data(rhs.m_data), m_length{rhs.m_length}, m_capacity{rhs.m_capacity} @@ -121,12 +122,12 @@ class Vector { Vector output{}; auto status = initializeWithCapacity(output, count, allocator); if (status != FudStatus::Success) { - return status; + return FudError{status}; } - return output; + return Okay>{std::move(output)}; } - static Result, FudStatus> initializeWithSize( + static FudStatus initializeWithSize( Vector& output, size_t count, Allocator* allocator = &globalFudAllocator) @@ -145,7 +146,8 @@ class Vector { const auto* ptr = new (output.m_data + index) T(); fudAssert(ptr != nullptr); } - return output; + + return FudStatus::Success; } template @@ -157,20 +159,20 @@ class Vector { Vector output{}; auto status = initializeWithSizeFallible(output, count, std::forward(builder), allocator); if (status != FudStatus::Success) { - return status; + return FudError{status}; } - return output; + return Okay>{std::move(output)}; } template - static Result, FudStatus> initializeWithSizeFallible( + static FudStatus initializeWithSizeFallible( Vector& output, size_t count, Builder&& builder, Allocator* allocator = &globalFudAllocator) { - using BuilderResult = decltype(std::forward(builder)()); - static_assert(std::is_same_v()); + // using BuilderResult = decltype(std::forward(builder)(T{})); + // static_assert(std::is_same_v); auto status = Vector::initializeWithCapacity(output, count, allocator); if (status != FudStatus::Success) { @@ -180,13 +182,13 @@ class Vector { output.m_length = count; for (size_t index = 0; index < count; ++index) { - auto builderResult{std::forward(builder)(output.m_data[index])}; - if (builderResult.isError()) { - return builderResult.takeError(); + auto builderStatus{std::forward(builder)(output.m_data[index])}; + if (builderStatus != FudStatus::Success) { + return builderStatus; } } - return output; + return FudStatus::Success; } static Result, FudStatus> from(const Vector& rhs, Option allocatorOption = NullOpt) @@ -356,7 +358,7 @@ class Vector { auto status = FudStatus::Success; if (m_capacity > 0) { - status = m_allocator->deallocate(reinterpret_cast(m_data), m_capacity); + m_allocator->deallocate(reinterpret_cast(m_data), m_capacity); } m_data = dataPtr; @@ -672,10 +674,7 @@ class Vector { auto status = clear(); if (m_data != nullptr && m_allocator != nullptr) { - auto deallocStatus = m_allocator->deallocate(reinterpret_cast(m_data), m_capacity); - if (status == FudStatus::Success) { - status = deallocStatus; - } + m_allocator->deallocate(reinterpret_cast(m_data), m_capacity); } m_allocator = nullptr; -- cgit v1.2.3