mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09: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: 55383998b1
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>
|
template<typename T>
|
||||||
requires(IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
|
requires(IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
|
||||||
|
AK_MAKE_DEFAULT_COPYABLE(Optional);
|
||||||
|
AK_MAKE_DEFAULT_MOVABLE(Optional);
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
friend class Optional;
|
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>
|
template<typename U>
|
||||||
ALWAYS_INLINE Optional(Optional<U>& other)
|
ALWAYS_INLINE Optional(Optional<U>& other)
|
||||||
requires(CanBePlacedInOptional<U>)
|
requires(CanBePlacedInOptional<U>)
|
||||||
|
@ -402,25 +394,6 @@ public:
|
||||||
other.m_pointer = nullptr;
|
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>
|
template<typename U>
|
||||||
ALWAYS_INLINE Optional& operator=(Optional<U>& other)
|
ALWAYS_INLINE Optional& operator=(Optional<U>& other)
|
||||||
requires(CanBePlacedInOptional<U>)
|
requires(CanBePlacedInOptional<U>)
|
||||||
|
|
|
@ -247,7 +247,6 @@ TEST_CASE(move_optional_reference)
|
||||||
y = move(x);
|
y = move(x);
|
||||||
EXPECT_EQ(y.has_value(), true);
|
EXPECT_EQ(y.has_value(), true);
|
||||||
EXPECT_EQ(y.value(), 3);
|
EXPECT_EQ(y.value(), 3);
|
||||||
EXPECT_EQ(x.has_value(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(short_notation_reference)
|
TEST_CASE(short_notation_reference)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue