Template Class IntrusivePtr¶
Defined in File intrusive_ptr.hpp
Class Documentation¶
-
template<typename
T>
classwrench::IntrusivePtr¶ The
IntrusivePtrtype is a shared pointer implementation which is intrusive. The reference count is stored in the intrusive pointer. It has a smaller memory footprint thanstd::shared_ptrand usually gives better performance.It additionally requires classes to inherit from
IntrusivePtrEnabled, which allows for custom specialization of the deleter and referenc types, for single/multi-threaded use cases.For a non-thread-safe, single-threaded optimized referencing, use
SingleThreadedRefTracker, while for a thread-safe, multi-threaded optimized referencing, usingMultiThreadedRefTracker.Instances of instrusive pointer types should be create with
make_intrusive_ptrorallcoate_intrusive_ptrrather than through direct construction.- Template Parameters
T: The type to wrap in an intrusive pointer.
Public Types
-
using
IntrusiveEnabledBase= IntrusivePtrEnabled<typename T::Enabled, typename T::DeleterType, typename T::RefTracker>¶ Defines the type of intrusive enabled base for the type T.
Public Functions
-
IntrusivePtr() noexcept = default¶ Default constructor.
-
IntrusivePtr(Ptr data) noexcept¶ Constructor which takes a pointer
ptr.- Parameters
data: A pointer to the data.
-
IntrusivePtr(const IntrusivePtr &other) noexcept = default¶ Copy constructor to create the intrusive pointer from
other.
-
IntrusivePtr(IntrusivePtr &&other) noexcept = default¶ Move the
otherintrusive pointer into this one.- Parameters
other: The other intrusive pointer to move into this one.
-
template<typename
U>IntrusivePtr(const IntrusivePtr<U> &other) noexcept¶ Copy constructor to create the intrusive pointer from
other. This will fail at compile time if U is not derived from T, or convertible to T.- Parameters
other: The other intrusive pointer to copy from.
- Template Parameters
U: The type of the other’s pointed to data.
-
template<typename
U>IntrusivePtr(IntrusivePtr<U> &&other) noexcept¶ Moves the
otherintrusive pointer into this one. This will fail at compile time if U is not derived from T or is convertible to T.- Parameters
other: The other type to move into this one.
-
~IntrusivePtr() noexcept¶ Destructor to clean up the pointer.
-
auto operator= (const IntrusivePtr &other) noexcept -> IntrusivePtr & Copy assignment operator to set the intrusive pointer from the
otherintrusive pointer.- Parameters
other: The other pointer to set this one from.
-
auto operator= (IntrusivePtr &&other) noexcept -> IntrusivePtr & Move assignment operator to move the
otherintrusive pointer into this one.- Parameters
other: The other pointer to move into this one.
-
template<typename U> auto operator= (const IntrusivePtr< U > &other) -> IntrusivePtr & Copy assignment operator to set the intrusive pointer from the
otherintrusive pointer, which wraps a different type to this one. If the type of theotheris not a base of T, or convertible to T, then this will cause a compile time error.- Parameters
other: The other pointer to set this one from.
- Template Parameters
U: The type of the other pointer.
-
template<typename U> auto operator= (IntrusivePtr< U > &&other) noexcept -> IntrusivePtr & Move assignment operator to move the
otherintrusive pointer into this one. This will fail if U is not derived from T or convertible to T.- Parameters
other: The other pointer to set this one from.
- Template Parameters
U: The type of the other pointer.
-
auto operator* () noexcept -> Ref Returns a reference to the data.
-
auto operator* () const noexcept -> ConstRef Returns a const reference to the data.
-
auto operator-> () noexcept -> Ptr Returns a pointer to the data.
-
auto operator-> () const noexcept -> ConstPtr Returns a const pointer to the data.
-
auto get () noexcept -> Ptr Returns a pointer to the data.
-
auto get () const noexcept -> ConstPtr Returns a const pointer to the data.
-
operator bool() const noexcept¶ Returns true if the data is not a nullptr.
-
auto operator== (const IntrusivePtr &other) const noexcept -> bool Returns true if the pointer to
other'sdata is the same as the pointer to this data.- Parameters
other: The other pointer to compare with.
-
auto operator!= (const IntrusivePtr &other) const noexcept -> bool Returns true if the pointer to
other'sdata is not the same as the pointer to this data.- Parameters
other: The other pointer to compare with.
-
auto reset () noexcept -> void Resets the intrusive pointer by releasing the reference, and resetting the pointer to the data.