The OpenD Programming Language

any

Checks if _any of the elements satisfies pred. !any can be used to verify that none of the elements satisfy pred. This is sometimes called exists in other languages.

template any(alias pred = "a")
bool
any
(
Range
)
(
Range range
)
if (
isInputRange!Range &&
(
__traits(isTemplate, pred) ||
is(typeof(unaryFun!pred(range.front)))
)
)

Members

Functions

any
bool any(Range range)

Returns true if and only if the input range range is non-empty and _any value found in range satisfies the predicate pred. Performs (at most) O(range.length) evaluations of pred.

Examples

import std.ascii : isWhite;
assert( all!(any!isWhite)(["a a", "b b"]));
assert(!any!(all!isWhite)(["a a", "b b"]));

any can also be used without a predicate, if its items can be evaluated to true or false in a conditional statement. !any can be a convenient way to quickly test that none of the elements of a range evaluate to true.

int[3] vals1 = [0, 0, 0];
assert(!any(vals1[])); //none of vals1 evaluate to true

int[3] vals2 = [2, 0, 2];
assert( any(vals2[]));
assert(!all(vals2[]));

int[3] vals3 = [3, 3, 3];
assert( any(vals3[]));
assert( all(vals3[]));

Meta