mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 12:30:31 +00:00
AK: Add NonnullOwnPtr::swap() as well for symmetry
This commit is contained in:
parent
05836757c6
commit
d394267f50
Notes:
sideshowbarker
2024-07-19 09:57:23 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d394267f503
1 changed files with 21 additions and 10 deletions
|
@ -100,11 +100,8 @@ public:
|
||||||
RETURN_TYPESTATE(unconsumed)
|
RETURN_TYPESTATE(unconsumed)
|
||||||
NonnullOwnPtr& operator=(NonnullOwnPtr&& other)
|
NonnullOwnPtr& operator=(NonnullOwnPtr&& other)
|
||||||
{
|
{
|
||||||
if (this != &other) {
|
NonnullOwnPtr ptr(move(other));
|
||||||
delete m_ptr;
|
swap(ptr);
|
||||||
m_ptr = other.leak_ptr();
|
|
||||||
ASSERT(m_ptr);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,11 +109,8 @@ public:
|
||||||
RETURN_TYPESTATE(unconsumed)
|
RETURN_TYPESTATE(unconsumed)
|
||||||
NonnullOwnPtr& operator=(NonnullOwnPtr<U>&& other)
|
NonnullOwnPtr& operator=(NonnullOwnPtr<U>&& other)
|
||||||
{
|
{
|
||||||
if (this != static_cast<void*>(&other)) {
|
NonnullOwnPtr ptr(move(other));
|
||||||
delete m_ptr;
|
swap(ptr);
|
||||||
m_ptr = other.leak_ptr();
|
|
||||||
ASSERT(m_ptr);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +144,17 @@ public:
|
||||||
operator bool() const = delete;
|
operator bool() const = delete;
|
||||||
bool operator!() const = delete;
|
bool operator!() const = delete;
|
||||||
|
|
||||||
|
void swap(NonnullOwnPtr& other)
|
||||||
|
{
|
||||||
|
::swap(m_ptr, other.m_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename U>
|
||||||
|
void swap(NonnullOwnPtr<U>& other)
|
||||||
|
{
|
||||||
|
::swap(m_ptr, other.m_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
|
@ -183,6 +188,12 @@ inline const LogStream& operator<<(const LogStream& stream, const NonnullOwnPtr<
|
||||||
return stream << value.ptr();
|
return stream << value.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
inline void swap(NonnullOwnPtr<T>& a, NonnullOwnPtr<U>& b)
|
||||||
|
{
|
||||||
|
a.swap(b);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::make;
|
using AK::make;
|
||||||
|
|
Loading…
Reference in a new issue