indexOf

Evaluates to the index of the first element where Pred!(Args[i]) is true.

If Pred!(Args[i]) is not true for any elements, then the result is -1.

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

template indexOf (
alias Pred
Args...
) {
enum ptrdiff_t indexOf;
}

Examples

import phobos.sys.traits : isInteger, isSameSymbol, isSameType;

alias Types1 = AliasSeq!(string, int, long, char[], ubyte, int);
alias Types2 = AliasSeq!(float, double, int[], char[], void);

static assert(indexOf!(isInteger, Types1) == 1);
static assert(indexOf!(isInteger, Types2) == -1);

static assert(indexOf!(isSameType!ubyte, Types1) == 4);
static assert(indexOf!(isSameType!ubyte, Types2) == -1);

int i;
int j;
string s;
int foo() { return 0; }
alias Symbols = AliasSeq!(i, j, foo);
static assert(indexOf!(isSameSymbol!j, Symbols) == 1);
static assert(indexOf!(isSameSymbol!s, Symbols) == -1);

// Empty AliasSeq.
static assert(indexOf!isInteger == -1);

// The predicate does not compile with all of the arguments,
// so indexOf does not compile.
static assert(!__traits(compiles, indexOf!(isSameType!int, long, int, 42)));

Meta