diff options
Diffstat (limited to 'include/fud_option.hpp')
-rw-r--r-- | include/fud_option.hpp | 17 |
1 files changed, 11 insertions, 6 deletions
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) { } |