all

Checks if all of the elements verify pred.

  1. bool all(Slices slices)
    template all(alias pred = "a")
    @optmath
    static if(__traits(isSame, naryFun!pred, pred))
    @optmath
    bool
    all
    (
    Slices...
    )
    (
    scope Slices slices
    )
    if (
    (
    Slices.length == 1 ||
    !__traits(isSame, pred, "a")
    )
    &&
    Slices.length
    )
  2. alias all = .all!(naryFun!pred)

Members

Aliases

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

Functions

all
bool all(Slices slices)

Parameters

pred

The predicate. Optimization: all!"a" has accelerated specialization for slices created with mir.ndslice.topology.bitwise, mir.ndslice.allocation.bitSlice.

Examples

Ranges and arrays

import std.range : iota;
// 0 1 2 3 4 5
auto r = iota(6);

assert(r.all!"a < 6");
assert(!r.all!"a < 5");
import mir.ndslice.topology : iota;

// 0 1 2
// 3 4 5
auto sl = iota(2, 3);

assert(sl.all!"a < 6");
assert(!sl.all!"a < 5");

Multiple slices

import mir.ndslice.topology : iota;

// 0 1 2
// 3 4 5
auto sl = iota(2, 3);

assert(all!"a - b == 0"(sl, sl));

Zipped slices

import mir.ndslice.topology : iota, zip;

// 0 1 2
// 3 4 5
auto sl = iota(2, 3);


assert(zip!true(sl, sl).all!"a.a - a.b == 0");

Mutation on-the-fly

import mir.ndslice.allocation : slice;
import mir.ndslice.topology : as, iota;

// 0 1 2
// 3 4 5
auto sl = iota(2, 3).as!double.slice;

static bool pred(T)(ref T a)
{
    if (a < 4)
    {
        a = 8;
        return true;
    }
    return false;
}

assert(!sl.all!pred);

// sl was changed
assert(sl == [[8, 8, 8],
              [8, 4, 5]]);

Meta