Mercurial > projects > qtd
comparison qt/qtd/Meta.d @ 319:894d40eb89b6 signals
new signals and slots syntax. have to use prefixes now: signal_fooed and slot_onFooed
author | eldar_ins@eldar-laptop |
---|---|
date | Fri, 25 Dec 2009 21:48:32 +0500 |
parents | |
children | 5c6455c4889b |
comparison
equal
deleted
inserted
replaced
318:ce07227f00c1 | 319:894d40eb89b6 |
---|---|
1 module qt.qtd.Meta; | |
2 | |
3 import std.traits; | |
4 import std.typetuple; | |
5 | |
6 // Various compile time utilities | |
7 | |
8 public bool ctfeStartsWith(T)(T[] source, T[] pattern) | |
9 { | |
10 return source.length >= pattern.length && source[0 .. pattern.length] == pattern[]; | |
11 } | |
12 | |
13 // compile-time toString, maybe to!string is already working in CT | |
14 string __toString(long v) | |
15 { | |
16 if (v == 0) | |
17 return "0"; | |
18 | |
19 string ret; | |
20 | |
21 bool neg; | |
22 if (v < 0) | |
23 { | |
24 neg = true; | |
25 v = -v; | |
26 } | |
27 | |
28 while (v != 0) | |
29 { | |
30 ret = cast(char)(v % 10 + '0') ~ ret; | |
31 v = cast(long)(v / 10); | |
32 } | |
33 | |
34 if (neg) | |
35 ret = "-" ~ ret; | |
36 | |
37 return ret; | |
38 } | |
39 | |
40 // returns the type of a template parameter if there is one | |
41 template templateParam(U : V!(U), alias V) | |
42 { | |
43 alias U templateParam; | |
44 } | |
45 | |
46 // to workaround buggy foreach, returns a tuple of Ts of size I | |
47 template Repeat(T, int I) | |
48 { | |
49 static if (!I) alias TypeTuple!() Repeat; | |
50 else alias TypeTuple!(T, Repeat!(T, I - 1)) Repeat; | |
51 } | |
52 | |
53 //returns number of required function arguments, optional arguments excluded | |
54 int requiredArgCount(alias fn)() { | |
55 alias ParameterTypeTuple!(typeof(&fn)) P; | |
56 P p; | |
57 static if (P.length == 0) | |
58 return 0; | |
59 | |
60 foreach(i, _; P) | |
61 { | |
62 static if (!__traits(compiles, fn(p[0..$-i-1]))) | |
63 { | |
64 return p.length - i; | |
65 } | |
66 } | |
67 return 0; | |
68 } |