summaryrefslogtreecommitdiff
path: root/include/fud_option.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-03-30 23:08:43 -0500
committerDominick Allen <djallen@librehumanitas.org>2025-03-30 23:08:43 -0500
commitcb9fa588ba8144fcdd52ba4b83d69d93fb18066f (patch)
tree214574ca68c1551ec76e7fbb9e0263793180231d /include/fud_option.hpp
parent1d357adfa19725ee69fb267a363f1fd217b1272f (diff)
Add hash map.
Diffstat (limited to 'include/fud_option.hpp')
-rw-r--r--include/fud_option.hpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/include/fud_option.hpp b/include/fud_option.hpp
index 9d3068c..5a5611f 100644
--- a/include/fud_option.hpp
+++ b/include/fud_option.hpp
@@ -89,7 +89,16 @@ class Option {
static_cast<void>(nullOpt);
}
- constexpr Option(T value) noexcept : m_engaged{true}
+ constexpr Option(const Option& rhs) noexcept : m_data(rhs.m_data), m_engaged(rhs.m_engaged)
+ {
+ }
+
+ constexpr Option(Option&& rhs) noexcept : m_data(std::move(rhs.m_data)), m_engaged(rhs.m_engaged)
+ {
+ rhs.cleanup();
+ }
+
+ constexpr Option(const T& value) noexcept : m_engaged{true}
{
if constexpr (IsRef) {
new (m_data.data()) std::reference_wrapper<ValueType>(std::ref(value));
@@ -98,30 +107,30 @@ class Option {
}
}
- constexpr static Option take(T&& value) noexcept
+ constexpr Option(T&& value) noexcept requires (not IsRef) : m_engaged{true}
{
- Option option{};
- option.m_engaged = true;
if constexpr (IsRef) {
- new (option.m_data.data()) std::reference_wrapper<ValueType>(std::ref(value));
+ new (m_data.data()) std::reference_wrapper<ValueType>(std::ref(value));
} else {
- new (option.m_data.data()) ValueType(std::move(value));
+ new (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)
- {
- }
-
- constexpr Option(Option&& rhs) noexcept : m_data(std::move(rhs.m_data)), m_engaged(rhs.m_engaged)
+ constexpr ~Option() noexcept
{
- rhs.cleanup();
+ destroy();
}
- constexpr ~Option() noexcept
+ constexpr static Option take(T&& value) noexcept
{
- destroy();
+ Option option{};
+ option.m_engaged = true;
+ 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;
}
Option& operator=(const Option& rhs) noexcept