From c3cf6df863828798ed8230b0f0966bcf3b2d08dd Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sun, 27 Oct 2024 21:50:16 -0500 Subject: Excise std::optional. --- include/fud_option.hpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'include/fud_option.hpp') 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(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(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) { } -- cgit v1.2.3