Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 19, 2013 comparing two arrays .. | ||||
---|---|---|---|---|
| ||||
Is there a built in function or operator in D that can compare two arrays (prefereably any dimensional) for being elementwise equal? thnak you |
November 19, 2013 Re: comparing two arrays .. | ||||
---|---|---|---|---|
| ||||
Posted in reply to seany | On Tuesday, 19 November 2013 at 14:12:14 UTC, seany wrote:
> Is there a built in function or operator in D that can compare two arrays (prefereably any dimensional) for being elementwise equal?
a == b works on single dimension. Not sure about beyond that though.
|
November 19, 2013 Re: comparing two arrays .. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | Adam D. Ruppe:
> a == b works on single dimension. Not sure about beyond that though.
It works on nD arrays:
void main() {
immutable m1 = [[1, 2], [3, 4]];
immutable m2 = [[1, 2], [3, 4]];
immutable m3 = [[1, 2], [3, 5]];
assert(m1 == m2);
assert(m1 != m3);
assert(m1 < m3);
}
Bye,
bearophile
|
November 19, 2013 Re: comparing two arrays .. | ||||
---|---|---|---|---|
| ||||
Posted in reply to seany Attachments:
| You'd usually find stuff like this (i.e. generic algorithms that act on collections) in std.algorithms http://dlang.org/phobos/std_algorithm.html#equal On Tue, Nov 19, 2013 at 3:12 PM, seany <seany@uni-bonn.de> wrote: > Is there a built in function or operator in D that can compare two arrays (prefereably any dimensional) for being elementwise equal? > > thnak you > |
Copyright © 1999-2021 by the D Language Foundation