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