The OpenD Programming Language

isLikeVariant

Same as isVariant, but matches for alias this variant types (requires DMD FE 2.100.0 or later)

enum bool isLikeVariant(T);

Examples

static struct CustomVariant
{
    Variant!(int, string) data;
    alias data this;
    this(T)(T v) { data = v; }
    ref typeof(this) opAssign(T)(T v)
    {
        data = v;
        return this;
    }
}

static assert(isLikeVariant!(Variant!(int, string)));
static assert(isLikeVariant!(const Variant!(int[], string)));
static assert(isLikeVariant!(Nullable!(int, string)));
static assert(!isLikeVariant!int);

static assert(!isVariant!CustomVariant);
static assert(isLikeVariant!CustomVariant);

CustomVariant customVariant = 5;
assert(customVariant.match!(
    (string s) => false,
    (int n) => true
));

Meta