mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Allow Optional<T> to be constructed by OptionalNone()
This is needed by the Jakt runtime too.
This commit is contained in:
parent
12e4cd3b77
commit
cc0b970d81
Notes:
sideshowbarker
2024-07-17 08:27:05 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/cc0b970d81 Pull-request: https://github.com/SerenityOS/serenity/pull/16396 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling ✅
1 changed files with 15 additions and 0 deletions
|
@ -44,6 +44,10 @@ using ConditionallyResultType = typename Detail::ConditionallyResultType<conditi
|
|||
template<typename>
|
||||
class Optional;
|
||||
|
||||
struct OptionalNone {
|
||||
explicit OptionalNone() = default;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
requires(!IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
|
||||
template<typename U>
|
||||
|
@ -56,6 +60,16 @@ public:
|
|||
|
||||
ALWAYS_INLINE Optional() = default;
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional(V) { }
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional& operator=(V)
|
||||
{
|
||||
clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef AK_HAS_CONDITIONALLY_TRIVIAL
|
||||
Optional(Optional const& other)
|
||||
requires(!IsCopyConstructible<T>)
|
||||
|
@ -115,6 +129,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename U = T>
|
||||
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
|
||||
ALWAYS_INLINE explicit(!IsConvertible<U&&, T>) Optional(U&& value)
|
||||
requires(!IsSame<RemoveCVReference<U>, Optional<T>> && IsConstructible<T, U &&>)
|
||||
: m_has_value(true)
|
||||
|
|
Loading…
Reference in a new issue