Unique

$(D_PSYMBOL Unique) stores an object that gets destroyed at the end of its scope.

Constructors

this
this(Payload!T value, Allocator allocator)
this(Allocator allocator)

Takes ownership over value, setting the counter to 1. value may be a pointer, an object or a dynamic array.

Destructor

~this
~this()

Destroys the owned object.

Postblit

this(this)
this(this)

$(D_PSYMBOL Unique) is noncopyable.

Alias This

get

Members

Functions

get
inout(Payload!T) get()
opAssign
typeof(this) opAssign(Payload!T rhs)
typeof(this) opAssign(typeof(null) )
typeof(this) opAssign(typeof(this) rhs)

Initialized this Unique and takes ownership over rhs.

opUnary
inout(T) opUnary()

Dereferences the pointer. It is defined only for pointers, not for reference types like classes, that can be accessed directly.

opUnary
inout(T) opUnary()
Undocumented in source. Be warned that the author may not have intended to support it.
release
Payload!T release()

Sets the internal pointer to $(D_KEYWORD). The allocator isn't changed.

Mixins

__anonymous
mixin DefaultAllocator
Undocumented in source.

Properties

isInitialized
bool isInitialized [@property getter]

Mixed In Members

From mixin DefaultAllocator

allocator_
Allocator allocator_;

Allocator.

this
this(Allocator allocator)
allocator
shared(Allocator) allocator [@property getter]

This property checks if the allocator was set in the constructor and sets it to the default one, if not.

Parameters

T

Value type.

Examples

auto p = defaultAllocator.make!int(5);
auto s = Unique!int(p, defaultAllocator);
assert(*s == 5);
static bool destroyed;

static struct F
{
    ~this() @nogc nothrow @safe
    {
        destroyed = true;
    }
}
{
    auto s = Unique!F(defaultAllocator.make!F(), defaultAllocator);
}
assert(destroyed);

Meta