Or

Combines multiple template predicates into a single template predicate using logical OR - i.e. for the resulting predicate to be true with a particular argument, at least one of the predicates must be true with that argument.

Evaluation is not short-circuited if a true result is encountered; the template predicate must be instantiable with all the elements.

template Or (
Preds...
) {}

Examples

import phobos.sys.traits : isFloatingPoint, isSignedInteger;

alias isSignedNumeric = Or!(isFloatingPoint, isSignedInteger);

static assert( isSignedNumeric!short);
static assert( isSignedNumeric!long);
static assert( isSignedNumeric!double);
static assert(!isSignedNumeric!uint);
static assert(!isSignedNumeric!ulong);
static assert(!isSignedNumeric!string);
static assert(!isSignedNumeric!(int*));

// An empty sequence of predicates always yields false.
alias alwaysFalse = Or!();
static assert(!alwaysFalse!int);

Predicates with multiple parameters are also supported. However, the number of parameters must match.

import phobos.sys.traits : isImplicitlyConvertible, isInteger;

enum isSameSize(T, U) = T.sizeof == U.sizeof;
alias convertibleOrSameSize = Or!(isImplicitlyConvertible, isSameSize);

static assert( convertibleOrSameSize!(int, int));
static assert( convertibleOrSameSize!(int, long));
static assert(!convertibleOrSameSize!(long, int));

static assert( convertibleOrSameSize!(int, float));
static assert( convertibleOrSameSize!(float, int));
static assert(!convertibleOrSameSize!(double, int));
static assert(!convertibleOrSameSize!(float, long));

static assert( convertibleOrSameSize!(int*, string*));

// Mismatched numbers of parameters.
alias doesNotWork = Or!(isInteger, isImplicitlyConvertible);
static assert(!__traits(compiles, doesNotWork!int));
static assert(!__traits(compiles, doesNotWork!(int, long)));

See Also

Meta