The OpenD Programming Language

minPos

Finds a backward index such that slice.backward(index) is minimal(maximal).

template minPos(alias pred = "a < b")
static if(__traits(isSame, naryFun!pred, pred))
Slice!(Iterator, N,
kind == Contiguous &&
N > 1
? Canonical : kind)
minPos
(
Iterator
size_t N
SliceKind kind
)
(
Slice!(Iterator, N, kind) slice
)

Members

Functions

minPos
Slice!(Iterator, N, kind == Contiguous && N > 1 ? Canonical : kind) minPos(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, 2,
    ].sliced(3, 4);

auto pos = s.minPos;

assert(pos == s[$ - 2 .. $, $ - 3 .. $]);
assert(pos.first == -4);
assert(s.backward(pos.shape) == -4);

pos = s.maxPos;

assert(pos == s[$ - 1 .. $, $ - 2 .. $]);
assert(pos.first == 7);
assert(s.backward(pos.shape) == 7);

See Also

Meta