cmp

Performs three-way recursive lexicographical comparison on two slices according to predicate pred. Iterating sl1 and sl2 in lockstep, cmp compares each N-1 dimensional element e1 of sl1 with the corresponding element e2 in sl2 recursively. If one of the slices has been finished,cmp returns a negative value if sl1 has fewer elements than sl2, a positive value if sl1 has more elements than sl2, and 0 if the ranges have the same number of elements.

  1. auto cmp(A sl1, B sl2)
    template cmp(alias pred = "a < b")
    @optmath
    static if(__traits(isSame, naryFun!pred, pred))
    cmp
    (
    A
    B
    )
    (
    scope A sl1
    ,
    scope B sl2
    )
    if (
    DimensionCount!A == DimensionCount!B
    )
  2. alias cmp = .cmp!(naryFun!pred)

Members

Aliases

cmp
alias cmp = .cmp!(naryFun!pred)
Undocumented in source.

Functions

cmp
auto cmp(A sl1, B sl2)

Parameters

pred

The predicate.

Examples

Ranges and arrays

import std.range : iota;

// 0 1 2 3 4 5
auto r1 = iota(0, 6);
// 1 2 3 4 5 6
auto r2 = iota(1, 7);

assert(cmp(r1, r1) == 0);
assert(cmp(r1, r2) < 0);
assert(cmp!"a >= b"(r1, r2) > 0);
import mir.ndslice.topology : iota;

// 0 1 2
// 3 4 5
auto sl1 = iota(2, 3);
// 1 2 3
// 4 5 6
auto sl2 = iota([2, 3], 1);

assert(cmp(sl1, sl1) == 0);
assert(cmp(sl1, sl2) < 0);
assert(cmp!"a >= b"(sl1, sl2) > 0);

Meta