mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
AK: Make it possible to swap() a NonnullRefPtr with itself
The generic swap() is not able to swap a NonnullRefPtr with itself, due to its use of a temporary and NonnullRefPtr asserting when trying to move() from an already move()'d instance.
This commit is contained in:
parent
604c5cb98e
commit
39b3c0ef7e
Notes:
sideshowbarker
2024-07-19 09:57:44 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/39b3c0ef7ef
2 changed files with 13 additions and 0 deletions
|
@ -267,6 +267,12 @@ inline const LogStream& operator<<(const LogStream& stream, const NonnullRefPtr<
|
|||
return stream << value.ptr();
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
inline void swap(NonnullRefPtr<T>& a, NonnullRefPtr<U>& b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::adopt;
|
||||
|
|
|
@ -73,4 +73,11 @@ TEST_CASE(assign_owner_of_self)
|
|||
EXPECT_EQ(child->ref_count(), 1);
|
||||
}
|
||||
|
||||
TEST_CASE(swap_with_self)
|
||||
{
|
||||
auto object = adopt(*new Object);
|
||||
swap(object, object);
|
||||
EXPECT_EQ(object->ref_count(), 1);
|
||||
}
|
||||
|
||||
TEST_MAIN(String)
|
||||
|
|
Loading…
Add table
Reference in a new issue