comparison test/arrays11.d @ 98:6789050b5ad1 trunk

[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references. Now uses the DMD _adEq(void[], void[], TypeInfo) runtime function for array equality comparison.
author lindquist
date Wed, 14 Nov 2007 23:39:10 +0100
parents
children
comparison
equal deleted inserted replaced
97:c4e161556a21 98:6789050b5ad1
1 module arrays11;
2
3 void ints()
4 {
5 int[] a = [1,2,3,4,5,6];
6 {assert(a == a);}
7
8 int[] b = [4,5,6,7,8,9];
9 {assert(a != b);}
10 {assert(a[3..$] == b[0..3]);}
11 }
12
13 void floats()
14 {
15 float[] a = [1.0f, 2.0f, 3.0f, 4.0f];
16 {assert(a == a);}
17
18 float[] b = [2.0f, 3.0f, 5.0f];
19 {assert(a != b);}
20 {assert(a[1..3] == b[0..2]);}
21 }
22
23 struct S
24 {
25 int i;
26 int j;
27
28 int opEquals(S s)
29 {
30 return (i == s.i) && (j == s.j);
31 }
32 }
33
34 void structs()
35 {
36 S[] a = [S(0,0), S(1,0), S(2,0), S(3,0)];
37 {assert(a == a);}
38 S[] b = [S(0,1), S(1,0), S(2,0), S(3,1)];
39 {assert(a != b);}
40 {assert(a[1..3] == b[1..3]);}
41
42 S[2] c = [S(2,0), S(3,1)];
43 {assert(c == b[2..$]);}
44 }
45
46 void main()
47 {
48 ints();
49 floats();
50 structs();
51 }