summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/fud_directory.hpp4
-rw-r--r--include/fud_option.hpp17
-rw-r--r--include/fud_string.hpp15
-rw-r--r--include/fud_utf8.hpp6
-rw-r--r--include/fud_utf8_iterator.hpp6
5 files changed, 29 insertions, 19 deletions
diff --git a/include/fud_directory.hpp b/include/fud_directory.hpp
index d2bd53d..e935950 100644
--- a/include/fud_directory.hpp
+++ b/include/fud_directory.hpp
@@ -21,12 +21,12 @@
#include "fud_result.hpp"
#include "fud_status.hpp"
#include "fud_string.hpp"
+#include "fud_option.hpp"
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <dirent.h>
-#include <optional>
namespace fud {
@@ -110,7 +110,7 @@ class Directory {
Result<DirectoryEntry, FudStatus> info();
- Result<std::optional<DirectoryEntry>, FudStatus> getNextEntry();
+ Result<Option<DirectoryEntry>, FudStatus> getNextEntry();
FudStatus reset();
diff --git a/include/fud_option.hpp b/include/fud_option.hpp
index 931ef82..3b0eb1b 100644
--- a/include/fud_option.hpp
+++ b/include/fud_option.hpp
@@ -92,17 +92,22 @@ class Option {
{
if constexpr (IsRef) {
new (m_data.data()) std::reference_wrapper<ValueType>(std::ref(value));
- if (!m_engaged) {
- std::abort();
- }
} else {
new (m_data.data()) ValueType(value);
- if (!m_engaged) {
- std::abort();
- }
}
}
+ constexpr static Option take(T&& value) noexcept
+ {
+ Option option{};
+ if constexpr (IsRef) {
+ new (option.m_data.data()) std::reference_wrapper<ValueType>(std::ref(value));
+ } else {
+ new (option.m_data.data()) ValueType(std::move(value));
+ }
+ return option;
+ }
+
constexpr Option(const Option& rhs) noexcept : m_data(rhs.m_data), m_engaged(rhs.m_engaged)
{
}
diff --git a/include/fud_string.hpp b/include/fud_string.hpp
index df03ad9..d2d3761 100644
--- a/include/fud_string.hpp
+++ b/include/fud_string.hpp
@@ -20,10 +20,11 @@
#include "fud_allocator.hpp"
#include "fud_assert.hpp"
+#include "fud_c_string.hpp"
+#include "fud_option.hpp"
#include "fud_result.hpp"
#include "fud_status.hpp"
#include "fud_string_view.hpp"
-#include "fud_c_string.hpp"
#include "fud_utf8.hpp"
#include <climits>
@@ -65,7 +66,7 @@ class String {
Array<size_t, sizeof...(cStrings)> lengths{};
Array<const char*, sizeof...(cStrings)> strPointers{};
size_t index = 0;
- for (const auto* cStringItem: {cStrings...}) {
+ for (const auto* cStringItem : {cStrings...}) {
const char* cString = nullptr;
if constexpr (std::is_same_v<decltype(cStringItem), const char*>) {
cString = cStringItem;
@@ -106,7 +107,11 @@ class String {
size_t cumulativeLength = 0;
for (size_t idx = 0; idx < strPointers.size(); ++idx) {
const auto* cString = strPointers[idx];
- auto copyStatus = copyMem(data + cumulativeLength, output.m_capacity - cumulativeLength, cString, lengths[idx]);
+ auto copyStatus = copyMem(
+ data + cumulativeLength,
+ output.m_capacity - cumulativeLength,
+ cString,
+ lengths[idx]);
fudAssert(copyStatus == FudStatus::Success);
cumulativeLength += lengths[idx];
}
@@ -189,7 +194,7 @@ class String {
FudStatus reserve(size_t newCapacity);
- [[nodiscard]] std::optional<utf8> back();
+ [[nodiscard]] Option<utf8> back();
[[nodiscard]] constexpr size_t remainingLength() const
{
@@ -211,7 +216,7 @@ class String {
FudStatus pushBack(const FudUtf8& letter);
- std::optional<utf8> pop();
+ Option<utf8> pop();
FudStatus append(const char* source);
diff --git a/include/fud_utf8.hpp b/include/fud_utf8.hpp
index 50e50aa..31c215a 100644
--- a/include/fud_utf8.hpp
+++ b/include/fud_utf8.hpp
@@ -20,10 +20,10 @@
#include "fud_array.hpp"
#include "fud_c_string.hpp"
+#include "fud_option.hpp"
#include "fud_unique_array.hpp"
#include <cstdint>
-#include <optional>
#include <type_traits>
namespace fud {
@@ -500,12 +500,12 @@ struct FudUtf8 {
return std::strong_ordering::greater;
}
- std::optional<Ascii> getAscii() const
+ Option<Ascii> getAscii() const
{
if (m_variant.index() == static_cast<size_t>(Utf8Type::Ascii)) {
return std::get<Ascii>(m_variant);
}
- return std::nullopt;
+ return NullOpt;
}
};
diff --git a/include/fud_utf8_iterator.hpp b/include/fud_utf8_iterator.hpp
index ec35927..25aaae6 100644
--- a/include/fud_utf8_iterator.hpp
+++ b/include/fud_utf8_iterator.hpp
@@ -19,10 +19,10 @@
#define FUD_UTF8_ITERATOR_HPP
#include "fud_string.hpp"
+#include "fud_option.hpp"
#include "fud_utf8.hpp"
#include <cstddef>
-#include <optional>
namespace fud {
@@ -47,8 +47,8 @@ class Utf8Iterator {
m_index = 0;
}
- [[nodiscard]] std::optional<FudUtf8> peek() const;
- std::optional<FudUtf8> next();
+ [[nodiscard]] Option<FudUtf8> peek() const;
+ Option<FudUtf8> next();
};
} // namespace fud