View source code
Display the source code in std/algorithm/comparison.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.algorithm.comparison.isSameLength
Checks if two or more 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.
bool isSameLength(Ranges...)
(
Ranges rs
)
if (allSatisfy!(isInputRange, Ranges));
If all ranges have a length
member or at least one is infinite,
_isSameLength
's complexity is Ο(1
). Otherwise, complexity is
Ο(n
), where n
is the smallest of the lengths of ranges with unknown
length.
Infinite ranges are considered of the same length. An infinite range has never the same length as a finite range.
Parameters
Name | Description |
---|---|
rs | two or more input ranges |
Returns
true
if both ranges have the same length, false
otherwise.
Example
assert(isSameLength([1, 2, 3], [4, 5, 6]));
assert(isSameLength([1, 2, 3], [4, 5, 6], [7, 8, 9]));
assert(isSameLength([0.3, 90.4, 23.7, 119.2], [42.6, 23.6, 95.5, 6.3]));
assert(isSameLength("abc", "xyz"));
assert(isSameLength("abc", "xyz", [1, 2, 3]));
int[] a;
int[] b;
assert(isSameLength(a, b));
assert(isSameLength(a, b, a, a, b, b, b));
assert(!isSameLength([1, 2, 3], [4, 5]));
assert(!isSameLength([1, 2, 3], [4, 5, 6], [7, 8]));
assert(!isSameLength([0.3, 90.4, 23.7], [42.6, 23.6, 95.5, 6.3]));
assert(!isSameLength("abcd", "xyz"));
assert(!isSameLength("abcd", "xyz", "123"));
assert(!isSameLength("abcd", "xyz", "1234"));
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.