From cb9fa588ba8144fcdd52ba4b83d69d93fb18066f Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sun, 30 Mar 2025 23:08:43 -0500 Subject: Add hash map. --- include/fud_option.hpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'include/fud_option.hpp') 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(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(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(std::ref(value)); + new (m_data.data()) std::reference_wrapper(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(std::ref(value)); + } else { + new (option.m_data.data()) ValueType(std::move(value)); + } + return option; } Option& operator=(const Option& rhs) noexcept -- cgit v1.2.3