mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +00:00
AK: Use Noncopyable.h
in Optional<T&>
This makes them trivially copyable/movable, silencing > "parameter is copied for each invocation" warnings on `Optional<T&>`, which are unnecessairy, since `Optional<T&>` is just a trivially copyable pointer. This creates a slight change in behaviour when moving out of an `Optional<T&>`, since the moved-from optional no longer gets cleared. Moved-from values should be considered to be in an undefined state, and if clearing a moved-from `Optional<T&>` is desired, you should be using `Optional<T&>::release_value()` instead.
This commit is contained in:
parent
7e78d7d332
commit
55383998b1
Notes:
github-actions[bot]
2024-12-04 00:59:45 +00:00
Author: https://github.com/yyny Commit: https://github.com/LadybirdBrowser/ladybird/commit/55383998b1d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2567 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/gmta ✅
2 changed files with 3 additions and 31 deletions
|
@ -336,6 +336,9 @@ private:
|
|||
|
||||
template<typename T>
|
||||
requires(IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
|
||||
AK_MAKE_DEFAULT_COPYABLE(Optional);
|
||||
AK_MAKE_DEFAULT_MOVABLE(Optional);
|
||||
|
||||
template<typename>
|
||||
friend class Optional;
|
||||
|
||||
|
@ -369,17 +372,6 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Optional(Optional const& other)
|
||||
: m_pointer(other.m_pointer)
|
||||
{
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Optional(Optional&& other)
|
||||
: m_pointer(other.m_pointer)
|
||||
{
|
||||
other.m_pointer = nullptr;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE Optional(Optional<U>& other)
|
||||
requires(CanBePlacedInOptional<U>)
|
||||
|
@ -402,25 +394,6 @@ public:
|
|||
other.m_pointer = nullptr;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Optional& operator=(Optional& other)
|
||||
{
|
||||
m_pointer = other.m_pointer;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Optional& operator=(Optional const& other)
|
||||
{
|
||||
m_pointer = other.m_pointer;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Optional& operator=(Optional&& other)
|
||||
{
|
||||
m_pointer = other.m_pointer;
|
||||
other.m_pointer = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE Optional& operator=(Optional<U>& other)
|
||||
requires(CanBePlacedInOptional<U>)
|
||||
|
|
|
@ -247,7 +247,6 @@ TEST_CASE(move_optional_reference)
|
|||
y = move(x);
|
||||
EXPECT_EQ(y.has_value(), true);
|
||||
EXPECT_EQ(y.value(), 3);
|
||||
EXPECT_EQ(x.has_value(), false);
|
||||
}
|
||||
|
||||
TEST_CASE(short_notation_reference)
|
||||
|
|
Loading…
Add table
Reference in a new issue