Base module

IntrusivePtr

Intrusive smart pointer for [RefCounted]({#ref classicy_1_1RefCounted #}) objects.

IntrusivePtr

#include <icy/memory.h>

Intrusive smart pointer for RefCounted objects.

Like std::shared_ptr but with zero allocation overhead:

  • No separate control block (refcount is embedded in the object)

  • Non-atomic refcount (safe for single-threaded libuv loops)

  • Same API as shared_ptr for easy migration

Public Methods

ReturnNameDescription
IntrusivePtr inline
IntrusivePtr inline
IntrusivePtr inline explicit
IntrusivePtr inline
IntrusivePtr inline
IntrusivePtr inline
IntrusivePtr inline
voidreset inlineReleases ownership of the current pointer, decrementing its refcount. The pointer is set to null.
voidreset inlineReleases the current pointer and takes ownership of p, incrementing its refcount.
T *get const inlineReturns the raw pointer without transferring ownership.
T &operator* const inlineDereferences the managed pointer.
T *operator-> const inlineMember access on the managed pointer.
operator bool const inline explicitReturns true if the pointer is non-null.
voidswap inlineSwaps the managed pointer with another IntrusivePtr.
voiddetach inlineRelease ownership without decrementing refcount. Used internally for move construction across types.
booloperator== const inline
booloperator!= const inline
booloperator== const inline
booloperator!= const inline
booloperator< const inline

IntrusivePtr

inline

inline IntrusivePtr() noexcept

IntrusivePtr

inline

inline IntrusivePtr(std::nullptr_t) noexcept

IntrusivePtr

inline explicit

inline explicit IntrusivePtr(T * p) noexcept

IntrusivePtr

inline

inline IntrusivePtr(const IntrusivePtr & r) noexcept

IntrusivePtr

inline

template<typename U> inline IntrusivePtr(const IntrusivePtr< U > & r) noexcept

IntrusivePtr

inline

inline IntrusivePtr(IntrusivePtr && r) noexcept

IntrusivePtr

inline

template<typename U> inline IntrusivePtr(IntrusivePtr< U > && r) noexcept

reset

inline

inline void reset() noexcept

Releases ownership of the current pointer, decrementing its refcount. The pointer is set to null.


reset

inline

inline void reset(T * p) noexcept

Releases the current pointer and takes ownership of p, incrementing its refcount.

Parameters

  • p New raw pointer to manage (may be nullptr).

get

const inline

inline T * get() const noexcept

Returns the raw pointer without transferring ownership.

Returns

Raw pointer to the managed object, or nullptr.


operator*

const inline

inline T & operator*() const noexcept

Dereferences the managed pointer.

Returns

Reference to the managed object.


operator->

const inline

inline T * operator->() const noexcept

Member access on the managed pointer.

Returns

Raw pointer to the managed object.


operator bool

const inline explicit

inline explicit operator bool() const noexcept

Returns true if the pointer is non-null.


swap

inline

inline void swap(IntrusivePtr & r) noexcept

Swaps the managed pointer with another IntrusivePtr.

Parameters


detach

inline

inline void detach() noexcept

Release ownership without decrementing refcount. Used internally for move construction across types.


operator==

const inline

inline bool operator==(const IntrusivePtr & r) const noexcept

operator!=

const inline

inline bool operator!=(const IntrusivePtr & r) const noexcept

operator==

const inline

inline bool operator==(std::nullptr_t) const noexcept

operator!=

const inline

inline bool operator!=(std::nullptr_t) const noexcept

operator<

const inline

inline bool operator<(const IntrusivePtr & r) const noexcept

Private Attributes

ReturnNameDescription
T *_ptr

_ptr

T * _ptr