unique_ptr

A unique pointer.

Unique pointers are a specialization of shared pointers, these pointers can not be copied, only moved. numem.core.lifetime contains functions for achieving moves.

You may borrow weak references from unique_ptr, these weak references may become invalid at any point, so make sure to check the state of the object using isValid.

Constructors

this
this(Ref!T ptr)

Constructs a shared_ptr with the given memory address.

this
this(inout(typeof(this)) src)

Disable copying.

Destructor

~this
~this()

Destructor.

Postblit

this(this)
this(this)
Undocumented in source.

Alias This

value

Members

Functions

borrow
weak_ptr!T borrow()

Borrows a weak reference from the shared pointer.

opPostMove
void opPostMove(typeof(this) other)

Post-move operator.

Properties

isValid
bool isValid [@property getter]

Whether the smart pointer value is still valid.

value
T value [@property getter]

The value stored within the smart pointer.

Examples

static
class A { }

auto p = unique_new!A();
auto b = move(p);

assert(!p.isValid);
assert(b.isValid);

Threadsafety: The internal reference count kept by shared_ptr is not atomic. As such you should take care with accessing the value and refcount stored within.

See Also

nulib.memory.shared_ptr.shared_ptr nulib.memory.weak_ptr.weak_ptr

Meta