diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qt/qtd/Meta.d	Fri Dec 25 21:48:32 2009 +0500
@@ -0,0 +1,68 @@
+module qt.qtd.Meta;
+
+import std.traits;
+import std.typetuple;
+
+// Various compile time utilities
+
+public bool ctfeStartsWith(T)(T[] source, T[] pattern)
+{
+    return source.length >= pattern.length && source[0 .. pattern.length] == pattern[];
+}
+
+// compile-time toString, maybe to!string is already working in CT
+string __toString(long v)
+{
+    if (v == 0)
+        return "0";
+
+    string ret;
+
+    bool neg;
+    if (v < 0)
+    {
+        neg = true;
+        v = -v;
+    }
+
+    while (v != 0)
+    {
+        ret = cast(char)(v % 10 + '0') ~ ret;
+        v = cast(long)(v / 10);
+    }
+
+    if (neg)
+        ret = "-" ~ ret;
+
+    return ret;
+}
+
+// returns the type of a template parameter if there is one
+template templateParam(U : V!(U), alias V)
+{
+    alias U templateParam;
+}
+
+// to workaround buggy foreach, returns a tuple of Ts of size I
+template Repeat(T, int I)
+{
+    static if (!I) alias TypeTuple!() Repeat;
+    else alias TypeTuple!(T, Repeat!(T, I - 1)) Repeat;
+}
+
+//returns number of required function arguments, optional arguments excluded
+int requiredArgCount(alias fn)() {
+    alias ParameterTypeTuple!(typeof(&fn)) P;
+    P p;
+    static if (P.length == 0)
+        return 0;
+    
+    foreach(i, _; P)
+    {
+        static if (!__traits(compiles, fn(p[0..$-i-1])))
+        {
+            return p.length - i;
+        }
+    }
+    return 0;
+}
\ No newline at end of file