The OpenD Programming Language

all

Checks if all of the elements verify pred.

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

Members

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