Rebindable

Rebindable!T is a container for T that permits managing T's lifetime explicitly.

Constructors

this
this(T value)

Construct a Rebindable from a value.

Members

Functions

destroy
void destroy()

Destroys the stored value. This is equivalent to a variable going out of scope.

get
CopyConstness!(This, T) get()

Get a copy of a previously stored value.

move
CopyConstness!(This, T) move()

Move-return the stored value by value. This is equivalent to get followed by destroy.

replace
void replace(T value)

Replace a currently stored value with a new value. This is equivalent to destroy followed by set.

set
void set(T value)

Set the Rebindable to a new value. Calling this function while an existing value is stored is undefined. The passed value is copied.

Examples

import rebindable.Rebindable : Rebindable;

struct DataStructure(T)
{
    private Rebindable!T store;

    this(T value)
    {
        this.store.set(value);
    }

    ~this()
    {
        this.store.destroy;
    }

    T get()
    {
        return this.store.get;
    }

    void set(T value)
    {
        this.store.replace(value);
    }
}

DataStructure!(const int) ds;

ds.set(5);
assert(ds.get == 5);

Meta