Header refcnt_ptr.h¶
A convenience layer over intrusive_shared_ptr for classes
that supply their own traits, plus the free functions that go with it.
-
template<class T>
using refcnt_ptr = intrusive_shared_ptr<T, typename T::refcnt_ptr_traits>¶ A specialization of
intrusive_shared_ptrfor the common case where you fully control the pointee’s class and can provide traits as a nested type namedrefcnt_ptr_traits. Theref_countedbase class provides such an implementation, soref_counted-derived classes work withrefcnt_ptrout of the box.
Factory functions¶
-
template<class T>
refcnt_ptr<T> refcnt_retain(T *ptr) noexcept¶ Create a
refcnt_ptrfrom a raw pointer and increment the reference count.
-
template<class T>
refcnt_ptr<T> refcnt_attach(T *ptr) noexcept¶ Create a
refcnt_ptrfrom a raw pointer without incrementing the reference count.
-
template<class T, class ...Args>
refcnt_ptr<T> make_refcnt(Args&&... args)¶ Create an instance of
Tvianew, forwarding the arguments to its constructor. Equivalent torefcnt_attach(new T(args...)).
Weak/strong conversions¶
-
template<class T>
refcnt_ptr<typename T::weak_value_type> weak_cast(const refcnt_ptr<T> &src)¶ -
template<class T>
refcnt_ptr<const typename T::weak_value_type> weak_cast(const refcnt_ptr<const T> &src)¶ If
Tprovides a typeweak_value_typeand a methodget_weak_ptr(), it is assumed to support weak references. These functions provide a convenient “cast” from a strong to a weak pointer, wrapping the call toget_weak_ptr().
-
template<class T>
refcnt_ptr<typename T::strong_value_type> strong_cast(const refcnt_ptr<T> &src) noexcept¶ -
template<class T>
refcnt_ptr<const typename T::strong_value_type> strong_cast(const refcnt_ptr<const T> &src) noexcept¶ If
Tprovides a typestrong_value_typeand a methodlock(), it is assumed to be a weak reference. These functions provide a convenient “cast” from a weak to a strong pointer, wrapping the call tolock().