boost::capy::neunique_ptr

A smart pointer with unique ownership, type‐erased deleter, and allocator support.

Synopsis

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.

Size

sizeof(neunique_ptr<T>) is two pointers (16 bytes on 64‐bit).

Thread Safety

Distinct neunique_ptr objects may be accessed concurrently. A single neunique_ptr object may not be accessed concurrently from multiple threads.

Types

Name

Description

element_type

The element type.

pointer

The pointer type.

Member Functions

Name

Description

neunique_ptr [constructor]

Constructors

~neunique_ptr [destructor]

Destructor.

operator= [deleted]

Assignment operators

get

Return the stored pointer.

operator*

Dereference the pointer.

operator‐>

Member access.

reset

reset overloads

swap

Swap with another pointer.

operator bool

Check if non‐empty.

Friends

Name Description

boost::capy::allocate_neunique

boost::capy::neunique_ptr

A smart pointer with unique ownership, type‐erased deleter, and allocator support.

Non-Member Functions

Name

Description

allocate_neunique

Create a neunique_ptr using a custom allocator.

allocate_neunique

Create a neunique_ptr for an array using a custom allocator.

make_neunique

Create a neunique_ptr for a single object.

make_neunique

Create a neunique_ptr for an array.

operator!=

Compare with nullptr.

operator!=

Compare for inequality.

operator<

Less‐than comparison with nullptr.

operator<

Less‐than comparison.

operator<=

Less‐than‐or‐equal comparison with nullptr.

operator<=

Less‐than‐or‐equal comparison.

operator==

Compare for equality.

operator==

Compare with nullptr.

operator>

Greater‐than comparison with nullptr.

operator>

Greater‐than comparison.

operator>=

Greater‐than‐or‐equal comparison with nullptr.

operator>=

Greater‐than‐or‐equal comparison.

swap

Swap two pointers.

Template Parameters

Name Description

T

The element type. May be incomplete at declaration. For arrays, use neunique_ptr<T[]>.

See Also

make_neunique, allocate_neunique

Created with MrDocs