summaryrefslogtreecommitdiff
path: root/include/fud_vector.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/fud_vector.hpp')
-rw-r--r--include/fud_vector.hpp66
1 files changed, 40 insertions, 26 deletions
diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp
index f90819a..2b5de9a 100644
--- a/include/fud_vector.hpp
+++ b/include/fud_vector.hpp
@@ -257,62 +257,68 @@ class Vector {
Result<Span<const T>, FudStatus> span() const
{
+ using RetType = Result<Span<const T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
- return Span{m_data, m_length};
+ return RetType::okay(Span{m_data, m_length});
}
Result<Span<T>, FudStatus> span()
{
+ using RetType = Result<Span<T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
- return Span{m_data, m_length};
+ return RetType::okay(Span{m_data, m_length});
}
Result<Span<const T>, FudStatus> span(size_t count) const
{
+ using RetType = Result<Span<const T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
if (count > m_length) {
- return FudStatus::ArgumentInvalid;
+ return RetType::error(FudStatus::ArgumentInvalid);
}
- return Span{m_data, count};
+ return RetType::okay(Span{m_data, count});
}
Result<Span<T>, FudStatus> span(size_t count)
{
+ using RetType = Result<Span<T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
if (count > m_length) {
- return FudStatus::ArgumentInvalid;
+ return RetType::error(FudStatus::ArgumentInvalid);
}
- return Span{m_data, count};
+ return RetType::okay(Span{m_data, count});
}
Result<Span<const T>, FudStatus> span(size_t start, size_t count) const
{
+ using RetType = Result<Span<const T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
if (SIZE_MAX - start < m_length || start + count > m_length) {
- return FudStatus::ArgumentInvalid;
+ return RetType::error(FudStatus::ArgumentInvalid);
}
- return Span{m_data + start, count};
+ return RetType::okay(Span{m_data + start, count});
}
Result<Span<T>, FudStatus> span(size_t start, size_t count)
{
+ using RetType = Result<Span<T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
if (SIZE_MAX - start < m_length || start + count > m_length) {
- return FudStatus::ArgumentInvalid;
+ return RetType::error(FudStatus::ArgumentInvalid);
}
- return Span{m_data + start, count};
+ return RetType::okay(Span{m_data + start, count});
}
FudStatus reserve(size_t count)
@@ -342,10 +348,15 @@ class Vector {
m_data[index].~T();
}
+ auto status = FudStatus::Success;
+ if (m_capacity > 0) {
+ status = m_allocator->deallocate(m_data, m_capacity);
+ }
+
m_data = dataPtr;
m_capacity = count;
- return FudStatus::Success;
+ return status;
}
FudStatus resize(size_t count)
@@ -394,24 +405,26 @@ class Vector {
Result<std::reference_wrapper<T>, FudStatus> get(size_t index)
{
+ using RetType = Result<std::reference_wrapper<T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
if (index >= m_length) {
- return FudStatus::IndexInvalid;
+ return RetType::error(FudStatus::IndexInvalid);
}
- return std::ref(m_data[index]);
+ return RetType::okay(std::ref(m_data[index]));
}
Result<const std::reference_wrapper<const T>, FudStatus> ref(size_t index) const
{
+ using RetType = Result<const std::reference_wrapper<const T>, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
if (index >= m_length) {
- return FudStatus::IndexInvalid;
+ return RetType::error(FudStatus::IndexInvalid);
}
- return std::cref(m_data[index]);
+ return RetType::okay(std::cref(m_data[index]));
}
constexpr Option<T&> front()
@@ -527,13 +540,14 @@ class Vector {
Result<T, FudStatus> popBack()
{
+ using RetType = Result<T, FudStatus>;
if (m_data == nullptr) {
- return FudStatus::ObjectInvalid;
+ return RetType::error(FudStatus::ObjectInvalid);
}
if (m_length == 0) {
- return FudStatus::Empty;
+ return RetType::error(FudStatus::Empty);
}
- auto result{std::move(m_data[m_length - 1])};
+ auto result{RetType::okay({std::move(m_data[m_length - 1])})};
m_length--;
m_data[m_length].~T();
return result;