mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
LibJS: Allow creating the specialized Optional<Value> from OptionalNone
This allows, for example: ThrowCompletionOr<Optional<Value>> foo() { return OptionalNone {}; } The constructors and constraints here are lifted verbatim from AK::Optional.
This commit is contained in:
parent
36553d4566
commit
3ca86cd044
Notes:
sideshowbarker
2024-07-16 17:12:03 +09:00
Author: https://github.com/trflynn89
Commit: 3ca86cd044
Pull-request: https://github.com/SerenityOS/serenity/pull/23041
1 changed files with 11 additions and 0 deletions
|
@ -602,6 +602,9 @@ public:
|
|||
|
||||
Optional() = default;
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional(V) { }
|
||||
|
||||
Optional(Optional<JS::Value> const& other)
|
||||
{
|
||||
if (other.has_value())
|
||||
|
@ -614,12 +617,20 @@ public:
|
|||
}
|
||||
|
||||
template<typename U = JS::Value>
|
||||
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
|
||||
explicit(!IsConvertible<U&&, JS::Value>) Optional(U&& value)
|
||||
requires(!IsSame<RemoveCVReference<U>, Optional<JS::Value>> && IsConstructible<JS::Value, U &&>)
|
||||
: m_value(forward<U>(value))
|
||||
{
|
||||
}
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional& operator=(V)
|
||||
{
|
||||
clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Optional& operator=(Optional const& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue