mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 11:36:13 +00:00
shared_ptr.hpp: Rewrite shared_ptr to single_ptr conversion
Logic felt non-intuitive and this method should be very explicit.
This commit is contained in:
parent
0cc655074d
commit
cfeb022340
1 changed files with 4 additions and 9 deletions
|
@ -451,23 +451,18 @@ namespace stx
|
|||
}
|
||||
}
|
||||
|
||||
// Converts to unique (single) ptr if reference is 1, otherwise returns null. Nullifies self.
|
||||
// Converts to unique (single) ptr if reference is 1. Nullifies self on success.
|
||||
template <typename U> requires PtrSame<T, U>
|
||||
explicit operator single_ptr<U>() && noexcept
|
||||
single_ptr<U> try_convert_to_single_ptr() noexcept
|
||||
{
|
||||
const auto o = d();
|
||||
|
||||
if (m_ptr && !--o->refs)
|
||||
if (const auto o = m_ptr ? d() : nullptr; o && o->refs == 1u)
|
||||
{
|
||||
// Convert last reference to single_ptr instance.
|
||||
o->refs.release(1);
|
||||
single_ptr<T> r;
|
||||
single_ptr<U> r;
|
||||
r.m_ptr = static_cast<decltype(r.m_ptr)>(std::exchange(m_ptr, nullptr));
|
||||
return r;
|
||||
}
|
||||
|
||||
// Otherwise, both pointers are gone. Didn't seem right to do it in the constructor.
|
||||
m_ptr = nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue