ifTestable

Tests whether pred(T) can be used as condition in an $(D_KEYWORD if)-statement or a ternary operator.

pred is an optional parameter. By default $(D_PSYMBOL ifTestable) tests whether T itself is usable as condition in an $(D_KEYWORD if)-statement or a ternary operator, i.e. if it a value of type T can be converted to a boolean.

template ifTestable (
T
alias pred = a => a
) {}

Members

Variables

ifTestable
enum bool ifTestable;
Undocumented in source.

Parameters

T

A type.

pred

Function with one argument.

Return Value

$(D_KEYWORD true) if pred(T) can be used as condition in an $(D_KEYWORD if)-statement or a ternary operator.

Examples

static assert(ifTestable!int);

static struct S1
{
}
static assert(!ifTestable!S1);

static struct S2
{
    bool opCast(T : bool)()
    {
        return true;
    }
}
static assert(ifTestable!S2);

Meta