isAssignable

Tests whether a value of type Rhs can be assigned to a variable of type Lhs.

If Rhs isn't specified, $(D_PSYMBOL isAssignable) tests whether a value of type Lhs can be assigned to a variable of the same type.

$(D_PSYMBOL isAssignable) tells whether Rhs can be assigned by value as well by reference.

template isAssignable (
Lhs
Rhs = Lhs
) {}

Members

Variables

isAssignable
enum bool isAssignable;
Undocumented in source.

Parameters

Lhs

Variable type.

Rhs

Expression type.

Return Value

$(D_KEYWORD true) if a value of type Rhs can be assigned to a variable of type Lhs, $(D_KEYWORD false) otherwise.

Examples

static struct S1
{
    @disable this();
    @disable this(this);
}
static struct S2
{
    void opAssign(S1 s) pure nothrow @safe @nogc
    {
    }
}
static struct S3
{
    void opAssign(ref S1 s) pure nothrow @safe @nogc
    {
    }
}
static assert(isAssignable!(S2, S1));
static assert(!isAssignable!(S3, S1));

static assert(isAssignable!(const(char)[], string));
static assert(!isAssignable!(string, char[]));

static assert(isAssignable!int);
static assert(!isAssignable!(const int, int));

Meta