# IntrusivePtr

<a id="intrusiveptr"></a>

# IntrusivePtr

```cpp
#include <icy/memory.h>

template<typename T>
class IntrusivePtr
```

[Defined in src/base/include/icy/memory.h:90](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L90)

Intrusive smart pointer for [RefCounted](https://auscaster.com/icey/docs/api-reference/icy-RefCounted.md#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

| Return | Name | Description |
|--------|------|-------------|
|  | [`IntrusivePtr`](#intrusiveptr-1) `inline` `noexcept` |  |
|  | [`IntrusivePtr`](#intrusiveptr-2) `inline` `noexcept` |  |
|  | [`IntrusivePtr`](#intrusiveptr-3) `inline` `explicit` `noexcept` |  |
|  | [`IntrusivePtr`](#intrusiveptr-4) `inline` `noexcept` |  |
|  | [`IntrusivePtr`](#intrusiveptr-5) `inline` `noexcept` |  |
|  | [`IntrusivePtr`](#intrusiveptr-6) `inline` `noexcept` |  |
|  | [`IntrusivePtr`](#intrusiveptr-7) `inline` `noexcept` |  |
|  | [`~IntrusivePtr`](#intrusiveptr-8) `inline` |  |
| [`IntrusivePtr`](#intrusiveptr) & | [`operator=`](#operator-30) `inline` `noexcept` |  |
| [`IntrusivePtr`](#intrusiveptr) & | [`operator=`](#operator-31) `inline` `noexcept` |  |
| [`IntrusivePtr`](#intrusiveptr) & | [`operator=`](#operator-32) `inline` `noexcept` |  |
| [`IntrusivePtr`](#intrusiveptr) & | [`operator=`](#operator-33) `inline` `noexcept` |  |
| `void` | [`reset`](#reset-3) `inline` `noexcept` | Releases ownership of the current pointer, decrementing its refcount. The pointer is set to null. |
| `void` | [`reset`](#reset-4) `inline` `noexcept` | Releases the current pointer and takes ownership of p, incrementing its refcount. |
| `T *` | [`get`](#get-2) `const` `inline` `noexcept` | Returns the raw pointer without transferring ownership. |
| `T &` | [`operator*`](#operator-34) `const` `inline` `noexcept` | Dereferences the managed pointer. |
| `T *` | [`operator->`](#operator-35) `const` `inline` `noexcept` | Member access on the managed pointer. |
|  | [`operator bool`](#operatorbool) `const` `inline` `explicit` `noexcept` | Returns true if the pointer is non-null. |
| `void` | [`swap`](#swap-5) `inline` `noexcept` | Swaps the managed pointer with another [IntrusivePtr](#intrusiveptr). |
| `void` | [`detach`](#detach) `inline` `noexcept` | Release ownership without decrementing refcount. Used internally for move construction across types. |
| `bool` | [`operator==`](#operator-36) `const` `inline` `noexcept` |  |
| `bool` | [`operator!=`](#operator-37) `const` `inline` `noexcept` |  |
| `bool` | [`operator==`](#operator-38) `const` `inline` `noexcept` |  |
| `bool` | [`operator!=`](#operator-39) `const` `inline` `noexcept` |  |
| `bool` | [`operator<`](#operator-40) `const` `inline` `noexcept` |  |

---

<a id="intrusiveptr-1"></a>

### IntrusivePtr

`inline` `noexcept`

```cpp
inline IntrusivePtr() noexcept
```

[Defined in src/base/include/icy/memory.h:93](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L93)

---

<a id="intrusiveptr-2"></a>

### IntrusivePtr

`inline` `noexcept`

```cpp
inline IntrusivePtr(std::nullptr_t) noexcept
```

[Defined in src/base/include/icy/memory.h:94](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L94)

---

<a id="intrusiveptr-3"></a>

### IntrusivePtr

`inline` `explicit` `noexcept`

```cpp
inline explicit IntrusivePtr(T * p) noexcept
```

[Defined in src/base/include/icy/memory.h:96](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L96)

---

<a id="intrusiveptr-4"></a>

### IntrusivePtr

`inline` `noexcept`

```cpp
inline IntrusivePtr(const IntrusivePtr & r) noexcept
```

[Defined in src/base/include/icy/memory.h:101](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L101)

---

<a id="intrusiveptr-5"></a>

### IntrusivePtr

`inline` `noexcept`

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

[Defined in src/base/include/icy/memory.h:107](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L107)

---

<a id="intrusiveptr-6"></a>

### IntrusivePtr

`inline` `noexcept`

```cpp
inline IntrusivePtr(IntrusivePtr && r) noexcept
```

[Defined in src/base/include/icy/memory.h:112](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L112)

---

<a id="intrusiveptr-7"></a>

### IntrusivePtr

`inline` `noexcept`

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

[Defined in src/base/include/icy/memory.h:118](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L118)

---

<a id="intrusiveptr-8"></a>

### ~IntrusivePtr

`inline`

```cpp
inline ~IntrusivePtr()
```

[Defined in src/base/include/icy/memory.h:123](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L123)

---

<a id="operator-30"></a>

### operator=

`inline` `noexcept`

```cpp
inline IntrusivePtr & operator=(const IntrusivePtr & r) noexcept
```

[Defined in src/base/include/icy/memory.h:129](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L129)

---

<a id="operator-31"></a>

### operator=

`inline` `noexcept`

```cpp
inline IntrusivePtr & operator=(IntrusivePtr && r) noexcept
```

[Defined in src/base/include/icy/memory.h:135](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L135)

---

<a id="operator-32"></a>

### operator=

`inline` `noexcept`

```cpp
inline IntrusivePtr & operator=(T * p) noexcept
```

[Defined in src/base/include/icy/memory.h:141](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L141)

---

<a id="operator-33"></a>

### operator=

`inline` `noexcept`

```cpp
inline IntrusivePtr & operator=(std::nullptr_t) noexcept
```

[Defined in src/base/include/icy/memory.h:147](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L147)

---

<a id="reset-3"></a>

### reset

`inline` `noexcept`

```cpp
inline void reset() noexcept
```

[Defined in src/base/include/icy/memory.h:155](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L155)

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

---

<a id="reset-4"></a>

### reset

`inline` `noexcept`

```cpp
inline void reset(T * p) noexcept
```

[Defined in src/base/include/icy/memory.h:162](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L162)

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `p` | `T *` | New raw pointer to manage (may be nullptr). |

---

<a id="get-2"></a>

### get

`const` `inline` `noexcept`

```cpp
inline T * get() const noexcept
```

[Defined in src/base/include/icy/memory.h:169](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L169)

Returns the raw pointer without transferring ownership. 
#### Returns
Raw pointer to the managed object, or nullptr.

---

<a id="operator-34"></a>

### operator*

`const` `inline` `noexcept`

```cpp
inline T & operator*() const noexcept
```

[Defined in src/base/include/icy/memory.h:173](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L173)

Dereferences the managed pointer. 
#### Returns
Reference to the managed object.

---

<a id="operator-35"></a>

### operator->

`const` `inline` `noexcept`

```cpp
inline T * operator->() const noexcept
```

[Defined in src/base/include/icy/memory.h:177](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L177)

Member access on the managed pointer. 
#### Returns
Raw pointer to the managed object.

---

<a id="operatorbool"></a>

### operator bool

`const` `inline` `explicit` `noexcept`

```cpp
inline explicit operator bool() const noexcept
```

[Defined in src/base/include/icy/memory.h:180](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L180)

Returns true if the pointer is non-null.

---

<a id="swap-5"></a>

### swap

`inline` `noexcept`

```cpp
inline void swap(IntrusivePtr & r) noexcept
```

[Defined in src/base/include/icy/memory.h:184](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L184)

Swaps the managed pointer with another [IntrusivePtr](#intrusiveptr).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `r` | [`IntrusivePtr`](#intrusiveptr) & | The other [IntrusivePtr](#intrusiveptr) to swap with. |

---

<a id="detach"></a>

### detach

`inline` `noexcept`

```cpp
inline void detach() noexcept
```

[Defined in src/base/include/icy/memory.h:188](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L188)

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

---

<a id="operator-36"></a>

### operator==

`const` `inline` `noexcept`

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

[Defined in src/base/include/icy/memory.h:190](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L190)

---

<a id="operator-37"></a>

### operator!=

`const` `inline` `noexcept`

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

[Defined in src/base/include/icy/memory.h:191](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L191)

---

<a id="operator-38"></a>

### operator==

`const` `inline` `noexcept`

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

[Defined in src/base/include/icy/memory.h:192](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L192)

---

<a id="operator-39"></a>

### operator!=

`const` `inline` `noexcept`

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

[Defined in src/base/include/icy/memory.h:193](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L193)

---

<a id="operator-40"></a>

### operator<

`const` `inline` `noexcept`

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

[Defined in src/base/include/icy/memory.h:194](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L194)

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| `T *` | [`_ptr`](#_ptr)  |  |

---

<a id="_ptr"></a>

### _ptr

```cpp
T * _ptr
```

[Defined in src/base/include/icy/memory.h:197](https://github.com/auscaster/icey/blob/main/src/base/include/icy/memory.h#L197)
