boost::capy::neunique_ptr
A smart pointer with unique ownership, type‐erased deleter, and allocator support.
Synopsis
Declared in <boost/capy/neunique_ptr.hpp>
template<class T>
class neunique_ptr;
Description
This class provides unique ownership semantics similar to std::unique_ptr, combined with features from std::shared_ptr:
-
Type‐erased deleters ‐ pointers with different deleters share the same static type
-
Allocator support ‐ custom allocators for the control block
-
Incomplete types ‐ the destructor is captured at construction
-
Aliasing ‐ the stored pointer can differ from the owned pointer
The implementation uses a control block to store the deleter and allocator, similar to std::shared_ptr but without reference counting.
Control Block Elision
When constructed from a raw pointer without a custom deleter or allocator, no control block is allocated. The pointer is deleted directly using delete. This optimization requires the type to be complete at destruction time.
Thread Safety
Distinct neunique_ptr objects may be accessed concurrently. A single neunique_ptr object may not be accessed concurrently from multiple threads.
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Assignment operators |
Return the stored pointer. |
|
Dereference the pointer. |
|
Member access. |
|
|
|
Swap with another pointer. |
|
Check if non‐empty. |
Friends
| Name | Description |
|---|---|
|
A smart pointer with unique ownership, type‐erased deleter, and allocator support. |
Non-Member Functions
Name |
Description |
Create a neunique_ptr using a custom allocator. |
|
Create a neunique_ptr for an array using a custom allocator. |
|
Create a neunique_ptr for a single object. |
|
Create a neunique_ptr for an array. |
|
Compare with nullptr. |
|
Compare for inequality. |
|
Less‐than comparison with nullptr. |
|
Less‐than comparison. |
|
Less‐than‐or‐equal comparison with nullptr. |
|
Less‐than‐or‐equal comparison. |
|
Compare for equality. |
|
Compare with nullptr. |
|
Greater‐than comparison with nullptr. |
|
Greater‐than comparison. |
|
Greater‐than‐or‐equal comparison with nullptr. |
|
Greater‐than‐or‐equal comparison. |
|
Swap two pointers. |
Template Parameters
| Name | Description |
|---|---|
T |
The element type. May be incomplete at declaration. For arrays, use |
See Also
make_neunique, allocate_neunique
Created with MrDocs