The OpenD Programming Language

findIndex

Finds an index such that pred(slices[0][index], ..., slices[$-1][index]) is true.

template findIndex(alias pred)
static if(__traits(isSame, naryFun!pred, pred))
Select!(DimensionCount!(Slices[0]) > 1, size_t[DimensionCount!(Slices[0])], size_t)
findIndex
(
Slices...
)
(
Slices slices
)
if (
Slices.length
)

Members

Functions

findIndex
Select!(DimensionCount!(Slices[0]) > 1, size_t[DimensionCount!(Slices[0])], size_t) findIndex(Slices slices)

Parameters

pred

A predicate.

Examples

Ranges and arrays

import std.range : iota;
// 0 1 2 3 4 5
auto sl = iota(5);
size_t index = sl.findIndex!"a == 3";

assert(index == 3);
assert(sl[index] == 3);

assert(sl.findIndex!(a => a == 8) == size_t.max);
import mir.ndslice.topology : iota;
// 0 1 2
// 3 4 5
auto sl = iota(2, 3);
size_t[2] index = sl.findIndex!(a => a == 3);

assert(sl[index] == 3);

index = sl.findIndex!"a == 6";
assert(index[0] == size_t.max);
assert(index[1] == size_t.max);

See Also

find, any. Optimization: findIndex!"a" has accelerated specialization for slices created with mir.ndslice.topology.bitwise, mir.ndslice.allocation.bitSlice.

Meta