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*/;
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)
29 else static if (is(aliasHelper
!(lst
[0]) == uda
) ||
is(typeof(lst
[0]) == uda
))
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
))
45 enum Find
= Find
!(lst
[1..$]);
47 enum getUDA
= Find
!(__traits(getAttributes
, T
));
59 @testuda1 struct Foo
{
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
));