countsAtMost

Check if r counts to at most maxCount elements.

@"complexity", "O(maxCount)"
bool
countsAtMost
(
R
)
(
R r
,
size_t maxCount
)
if (
isInputRange!R
)

Examples

static void test(R)(R x)
	if (isInputRange!R) {
	import std.algorithm.searching : count;
	immutable n = x.count;

	// below
	foreach (immutable i; 0 .. n) {
		assert(x.countsAtLeast(i));
		assert(!x.countsExactly(i));
		assert(!x.countsAtMost(i));
	}

	// at
	assert(x.countsAtLeast(n));
	assert(x.countsExactly(n));
	assert(x.countsAtMost(n));

	// above
	foreach (immutable i; n + 1 .. n + 10) {
		assert(!x.countsAtLeast(i));
		assert(!x.countsExactly(i));
		assert(x.countsAtMost(i));
	}
}

import std.algorithm.iteration : filter;
import std.range : iota;

test(3.iota.filter!(x => true));

int[3] x = [0, 1, 2];
test(x[]);

Meta