isSameLength

Checks if the two ranges have the same number of elements. This function is optimized to always take advantage of the length member of either range if it exists.

If both ranges have a length member, this function is O(1). Otherwise, this function is O(min(r1.length, r2.length)).

bool
isSameLength
(
Range1
Range2
)
(
Range1 r1
,
Range2 r2
)
if (
isInputRange!Range1 &&
&&
!isInfinite!Range1
&&
!isInfinite!Range2
)

Parameters

r1 Range1

a finite input range

r2 Range2

a finite input range

Return Value

Type: bool

true if both ranges have the same length, false otherwise.

Examples

assert(isSameLength([1, 2, 3], [4, 5, 6]));
assert(isSameLength([0.3, 90.4, 23.7, 119.2], [42.6, 23.6, 95.5, 6.3]));
assert(isSameLength("abc", "xyz"));

int[] a;
int[] b;
assert(isSameLength(a, b));

assert(!isSameLength([1, 2, 3], [4, 5]));
assert(!isSameLength([0.3, 90.4, 23.7], [42.6, 23.6, 95.5, 6.3]));
assert(!isSameLength("abcd", "xyz"));

Meta

Suggestion Box / Bug Report