mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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>
|
template<typename>
|
||||||
class Optional;
|
class Optional;
|
||||||
|
|
||||||
|
struct OptionalNone {
|
||||||
|
explicit OptionalNone() = default;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(!IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
|
requires(!IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
|
||||||
template<typename U>
|
template<typename U>
|
||||||
|
@ -56,6 +60,16 @@ public:
|
||||||
|
|
||||||
ALWAYS_INLINE Optional() = default;
|
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
|
#ifdef AK_HAS_CONDITIONALLY_TRIVIAL
|
||||||
Optional(Optional const& other)
|
Optional(Optional const& other)
|
||||||
requires(!IsCopyConstructible<T>)
|
requires(!IsCopyConstructible<T>)
|
||||||
|
@ -115,6 +129,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U = T>
|
template<typename U = T>
|
||||||
|
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
|
||||||
ALWAYS_INLINE explicit(!IsConvertible<U&&, T>) Optional(U&& value)
|
ALWAYS_INLINE explicit(!IsConvertible<U&&, T>) Optional(U&& value)
|
||||||
requires(!IsSame<RemoveCVReference<U>, Optional<T>> && IsConstructible<T, U &&>)
|
requires(!IsSame<RemoveCVReference<U>, Optional<T>> && IsConstructible<T, U &&>)
|
||||||
: m_has_value(true)
|
: m_has_value(true)
|
||||||
|
|
Loading…
Reference in a new issue