egra: some X11 hacks
[iv.d.git] / _obsolete_dont_use / udas.d
blobdbf83a5c52c0a0ac06ca85730529af5e385bf3b7
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // severely outdated! do not use!
18 module iv.udas /*is aliced*/;
19 import iv.alice;
21 private alias aliasHelper(alias T) = T;
22 private alias aliasHelper(T) = T;
25 template hasUDA(alias T, alias uda) {
26 static template Has(alias uda, lst...) {
27 static if (lst.length == 0)
28 enum Has = false;
29 else static if (is(aliasHelper!(lst[0]) == uda) || is(typeof(lst[0]) == uda))
30 enum Has = true;
31 else
32 enum Has = Has!(uda, lst[1..$]);
34 enum hasUDA = Has!(uda, __traits(getAttributes, T));
38 template getUDA(alias T, alias uda) {
39 template Find(lst...) {
40 static if (lst.length == 0)
41 static assert(0, "uda '"~uda.stringof~"' not found in type '"~T.stringof~"'");
42 else static if (is(aliasHelper!(lst[0]) == uda) || is(typeof(lst[0]) == uda))
43 enum Find = lst[0];
44 else
45 enum Find = Find!(lst[1..$]);
47 enum getUDA = Find!(__traits(getAttributes, T));
51 unittest {
52 enum testuda0;
53 struct testuda1 {}
55 struct A {
56 @A string bar;
59 @testuda1 struct Foo {
60 @A("foo")
61 int i;
62 @testuda0 string s;
65 static assert(!hasUDA!(Foo, A));
66 static assert(hasUDA!(Foo, testuda1));
67 static assert(hasUDA!(Foo.i, A));
68 static assert(getUDA!(Foo.i, A).bar == "foo");
70 //even uda-inception works
71 static assert(hasUDA!(getUDA!(Foo.i, A).bar, A));
72 static assert(!hasUDA!(getUDA!(Foo.i, A).bar, testuda1));