View source code
Display the source code in std/algorithm/comparison.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Template std.algorithm.comparison.equal
Compares two ranges for equality, as defined by predicate pred
(which is ==
by default).
Arguments
template equal(alias pred);
Functions
Function name | Description |
---|---|
equal |
Example
import std.math : approxEqual; import std.algorithm : equal; int[] a = [ 1, 2, 4, 3 ]; assert(!equal(a, a[1..$])); assert(equal(a, a)); // different types double[] b = [ 1.0, 2, 4, 3]; assert(!equal(a, b[1..$])); assert(equal(a, b)); // predicated: ensure that two vectors are approximately equal double[] c = [ 1.005, 2, 4, 3]; assert(equal!approxEqual(b, c));
Example
Tip
can itself be used as a predicate to other functions.
This can be very useful when the element type of a range is itself a
range. In particular, equal
can be its own predicate, allowing
range of range (of range...) comparisons.
equal
import std.range : iota, chunks; import std.algorithm : equal; assert(equal!(equal!equal)( [[[0, 1], [2, 3]], [[4, 5], [6, 7]]], iota(0, 8).chunks(2).chunks(2) ));