Add cast_intrusive() and make use of it in two spots

This commit is contained in:
Jon Siwek 2020-05-06 17:37:23 -07:00
parent c6f2e35af0
commit 6a1e4d61d1
3 changed files with 18 additions and 6 deletions

View file

@ -184,6 +184,18 @@ IntrusivePtr<T> make_intrusive(Ts&&... args)
return {AdoptRef{}, new T(std::forward<Ts>(args)...)};
}
/**
* Casts an @c IntrusivePtr object to another by way of static_cast on
* the underlying pointer.
* @param p The pointer of type @c U to cast to another type, @c T.
* @return The pointer, as cast to type @c T.
*/
template <class T, class U>
IntrusivePtr<T> cast_intrusive(IntrusivePtr<U> p) noexcept
{
return {AdoptRef{}, static_cast<T*>(p.release())};
}
// -- comparison to nullptr ----------------------------------------------------
/**