mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 05:05:32 +03:00
AK: Allow Optional<T&>
to be constructed by OptionalNone()
This is an extension of cc0b970d
but for the reference-handling
specialization of Optional.
This basically allow us to write code like:
```cpp
Optional<u8&> opt;
opt = OptionalNone{};
```
This commit is contained in:
parent
d777b279e3
commit
aaf54f8cf8
Notes:
sideshowbarker
2024-07-17 02:37:08 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/aaf54f8cf8 Pull-request: https://github.com/SerenityOS/serenity/pull/22078
@ -339,6 +339,16 @@ public:
|
||||
|
||||
ALWAYS_INLINE Optional() = default;
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional(V) { }
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional& operator=(V)
|
||||
{
|
||||
clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U = T>
|
||||
ALWAYS_INLINE Optional(U& value)
|
||||
requires(CanBePlacedInOptional<U&>)
|
||||
@ -409,6 +419,7 @@ public:
|
||||
|
||||
// Note: Disallows assignment from a temporary as this does not do any lifetime extension.
|
||||
template<typename U>
|
||||
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
|
||||
ALWAYS_INLINE Optional& operator=(U&& value)
|
||||
requires(CanBePlacedInOptional<U> && IsLvalueReference<U>)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user