diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-10-01 23:38:01 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-10-01 23:38:01 +0200 |
commit | 0f2d186fbd4cc637a359b1d62370174aebd2b80f (patch) | |
tree | 3852f378c6f25dae63e16355c9cccc8bcffb551c /asl/option.hpp | |
parent | def67bba57e7cfdf9942bc2c88a4ce484963f9d2 (diff) |
Some work on maybe_uninit & option
Diffstat (limited to 'asl/option.hpp')
-rw-r--r-- | asl/option.hpp | 17 |
1 files changed, 17 insertions, 0 deletions
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<is_object T>
class option
{
+ maybe_uninit<T> 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<T>)
+ {
+ if (m_has_value) { m_payload.uninit_unsafe(); }
+ }
+
};
} // namespace asl
|