From 0f2d186fbd4cc637a359b1d62370174aebd2b80f Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 1 Oct 2024 23:38:01 +0200 Subject: Some work on maybe_uninit & option --- asl/option.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'asl/option.hpp') diff --git a/asl/option.hpp b/asl/option.hpp index e71eb57..4793830 100644 --- a/asl/option.hpp +++ b/asl/option.hpp @@ -1,13 +1,30 @@ #pragma once #include "asl/meta.hpp" +#include "asl/maybe_uninit.hpp" namespace asl { +struct nullopt_t {}; +static constexpr nullopt_t nullopt{}; + template class option { + maybe_uninit m_payload; + bool m_has_value = false; + +public: + constexpr option() = default; + constexpr option(nullopt_t) {} // NOLINT(*-explicit-conversions) + + constexpr ~option() = default; + constexpr ~option() requires (!trivially_destructible) + { + if (m_has_value) { m_payload.uninit_unsafe(); } + } + }; } // namespace asl -- cgit