diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-10-28 23:52:48 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 2a10eaae094e48a157d55ec886aaa07b0d0be6c9 (patch) | |
tree | e334ce5d2de1604eb168a3269be887bbc078df70 /asl/option.hpp | |
parent | 46cc6bfc5f62bb45427ef7778ba5fc04d7a546da (diff) |
Some work on test framework & option
Diffstat (limited to 'asl/option.hpp')
-rw-r--r-- | asl/option.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
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<typename U>
+ // NOLINTNEXTLINE(*-explicit-conversions)
+ constexpr option(U&& value) requires constructible<T, U>
+ {
+ construct(ASL_FWD(value));
+ }
+
constexpr option(const option& other) requires copy_constructible<T>
{
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<typename T>
+option(T) -> option<T>;
+
} // namespace asl
|