annotate addon/template_10_traits.d @ 1630:d0efa3ae5522 default tip

run/mini/naked_asm5: New x86_64 ABI passes the arguments in reverse order.
author David Nadlinger <code@klickverbot.at>
date Sat, 23 Apr 2011 22:57:32 +0200
parents 9603ea1557fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
223
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
1 /*
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
2 Thor - D Metaprogramming Library
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
3 version zero
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
4 (c) 2004-2005 Aleksey Bobnev
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
5
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
6 Public Domain
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
7
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
8 Thanks go to:
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
9 Andrei Alexandrescu - for admirable book "Modern C++ Design" and Loki library
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
10 Andy Friesen - for apropos library, which actually pioneered meta-programming in D
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
11 */
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
12 /+module Thor.traits;+/
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
13 module addon.template_10_traits;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
14
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
15 private
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
16 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
17 /+import Thor.meta;+/
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
18 import addon.template_10_meta;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
19 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
20
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
21 template IsArray(T)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
22 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
23 static const bool IsArray = false;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
24 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
25
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
26 template IsArray(T : T[])
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
27 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
28 static const bool IsArray = true;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
29 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
30
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
31 template IsPointer(T)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
32 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
33 static const bool IsPointer = false;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
34 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
35
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
36 template IsPointer(T : T*)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
37 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
38 static const bool IsPointer = true;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
39 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
40
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
41 template IsObject(T)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
42 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
43 static const bool IsObject = false;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
44 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
45
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
46 template IsObject(T : Object)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
47 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
48 static const bool IsObject = true;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
49 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
50
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
51 template ElementType(T : T[])
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
52 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
53 alias T ElementType;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
54 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
55
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
56 template ElementType(T)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
57 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
58 alias T ElementType;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
59 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
60
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
61 template PointeeType(T : T*)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
62 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
63 alias T PointeeType;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
64 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
65
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
66 template PointeeType(T)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
67 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
68 alias T PointeeType;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
69 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
70
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
71 // type traits
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
72 template Traits(T)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
73 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
74 // IsConvertableTo
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
75 // can T be converted to X?
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
76
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
77 template IsConvertableTo(X)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
78 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
79 static bool IsConvertableTo = false;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
80 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
81
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
82 template IsConvertableTo(X : T)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
83 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
84 static bool IsConvertableTo = true;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
85 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
86
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
87 alias IsArray!(T) isArray;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
88 alias IsPointer!(T) isPointer;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
89 alias IsObject!(T) isObject;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
90
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
91 alias SelectType!((isArray),ElementType!(T),SelectType!((isPointer),PointeeType!(T),T)) subType;
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
92 }
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
93
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
94 template Inherits(Base : Object, Child : Object)
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
95 {
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
96 const bool Inherits = Traits!(Base).IsConvertableTo!(Child) && !Traits!(Child).IsConvertableTo!(Base);
9603ea1557fc template specialization bug
thomask
parents:
diff changeset
97 }