Mercurial > projects > ldc
annotate tests/mini/typeinfo10.d @ 1618:a87f1d6ff48e
Merge DMD r303: harmonize
---
dmd/expression.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++-----
dmd/expression.h | 8 +++++
dmd/template.c | 27 ++++++++++++-------
3 files changed, 95 insertions(+), 18 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:21 -0300 |
parents | 0a5f7890f327 |
children |
rev | line source |
---|---|
72 | 1 module typeinfo10; |
2 | |
3 struct S | |
4 { | |
5 long l; | |
6 float f; | |
7 void* vp; | |
8 | |
9 hash_t toHash() | |
10 { | |
11 return l + cast(size_t)f; | |
12 } | |
13 | |
14 int opEquals(S s) | |
15 { | |
16 return (s.l == l) && (s.f == f); | |
17 } | |
18 | |
19 int opCmp(S a) | |
20 { | |
21 if (l == a.l) { | |
22 return (f < a.f) ? -1 : (f > a.f) ? 1 : 0; | |
23 } | |
24 return (l < a.l) ? -1 : 1; | |
25 } | |
26 | |
27 char[] toString() | |
28 { | |
29 return "S instance"; | |
30 } | |
31 } | |
32 | |
33 void main() | |
34 { | |
35 S s=S(-1, 0); | |
36 S t=S(-1, 1); | |
37 S u=S(11,-1); | |
38 S v=S(12,13); | |
39 | |
40 { | |
41 assert(s == s); | |
42 assert(s != t); | |
43 assert(s != v); | |
44 assert(s < t); | |
45 assert(u > s); | |
46 assert(v > u); | |
47 } | |
48 | |
49 { | |
50 auto ti = typeid(S); | |
51 assert(ti.getHash(&s) == s.toHash()); | |
52 assert(ti.equals(&s,&s)); | |
53 assert(!ti.equals(&s,&t)); | |
54 assert(!ti.equals(&s,&v)); | |
55 assert(ti.compare(&s,&s) == 0); | |
56 assert(ti.compare(&s,&t) < 0); | |
57 assert(ti.compare(&u,&s) > 0); | |
58 assert(ti.compare(&v,&u) > 0); | |
59 { | |
60 auto tis = cast(TypeInfo_Struct)ti; | |
1442
0a5f7890f327
Adjust some more code that was depending on the function and delegate calling
Frits van Bommel <fvbommel wxs.nl>
parents:
341
diff
changeset
|
61 char[] delegate() structToString; |
0a5f7890f327
Adjust some more code that was depending on the function and delegate calling
Frits van Bommel <fvbommel wxs.nl>
parents:
341
diff
changeset
|
62 structToString.ptr = &s; |
0a5f7890f327
Adjust some more code that was depending on the function and delegate calling
Frits van Bommel <fvbommel wxs.nl>
parents:
341
diff
changeset
|
63 structToString.funcptr = tis.xtoString; |
0a5f7890f327
Adjust some more code that was depending on the function and delegate calling
Frits van Bommel <fvbommel wxs.nl>
parents:
341
diff
changeset
|
64 assert(structToString() == s.toString()); |
72 | 65 } |
66 } | |
67 } |