From 2a10eaae094e48a157d55ec886aaa07b0d0be6c9 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 28 Oct 2024 23:52:48 +0100 Subject: Some work on test framework & option --- asl/option.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'asl/option.hpp') diff --git a/asl/option.hpp b/asl/option.hpp index 7600252..ddd531d 100644 --- a/asl/option.hpp +++ b/asl/option.hpp @@ -40,6 +40,13 @@ public: constexpr option() = default; constexpr option(nullopt_t) {} // NOLINT(*-explicit-conversions) + template + // NOLINTNEXTLINE(*-explicit-conversions) + constexpr option(U&& value) requires constructible + { + construct(ASL_FWD(value)); + } + constexpr option(const option& other) requires copy_constructible { if (other.m_has_value) @@ -116,6 +123,30 @@ public: m_has_value = false; } } + + constexpr bool has_value() const { return m_has_value; } + + // @Todo Do we want this on rvalues? Or maybe some kind of unwrap? + constexpr T&& value() && + { + ASL_ASSERT(m_has_value); // @Todo Release assert + return ASL_MOVE(m_payload).as_init_unsafe(); + } + + constexpr T& value() & + { + ASL_ASSERT(m_has_value); // @Todo Release assert + return m_payload.as_init_unsafe(); + } + + constexpr const T& value() const& + { + ASL_ASSERT(m_has_value); // @Todo Release assert + return m_payload.as_init_unsafe(); + } }; +template +option(T) -> option; + } // namespace asl -- cgit