The OpenD Programming Language

minIndex

Finds an index such that slice[index] is minimal(maximal).

template minIndex(alias pred = "a < b")
static if(__traits(isSame, naryFun!pred, pred))
size_t[N]
minIndex
(
Iterator
size_t N
SliceKind kind
)
(
Slice!(Iterator, N, kind) slice
)

Members

Functions

minIndex
size_t[N] minIndex(Slice!(Iterator, N, kind) slice)

Parameters

pred

A predicate.

Examples

import mir.ndslice.slice: sliced;
auto s = [
    2, 6, 4, -3,
    0, -4, -3, 3,
    -3, -2, 7, 8,
    ].sliced(3, 4);

auto index = s.minIndex;

assert(index == [1, 1]);
assert(s[index] == -4);

index = s.maxIndex;

assert(index == [2, 3]);
assert(s[index] == 8);
import mir.ndslice.slice: sliced;
auto s = [
    -8, 6, 4, -3,
    0, -4, -3, 3,
    -3, -2, 7, 8,
    ].sliced(3, 4);

auto index = s.minIndex;

assert(index == [0, 0]);
assert(s[index] == -8);

See Also

Meta