1 module mutils.meta; 2 3 import std.meta; 4 import std.traits; 5 6 template removeEven(Arr...) { 7 static if (Arr.length > 2) { 8 alias removeEven = AliasSeq!(Arr[1], removeEven!(Arr[2 .. $])); 9 } else static if (Arr.length == 2) { 10 alias removeEven = AliasSeq!(Arr[1]); 11 } else { 12 alias removeEven = AliasSeq!(); 13 } 14 } 15 16 unittest { 17 static assert(is(removeEven!(int, float, long) == AliasSeq!(float))); 18 static assert(is(removeEven!(int, float, long, float) == AliasSeq!(float, float))); 19 } 20 21 template removeOdd(Arr...) { 22 static if (Arr.length > 2) { 23 alias removeOdd = AliasSeq!(Arr[0], removeOdd!(Arr[2 .. $])); 24 } else static if (Arr.length == 2) { 25 alias removeOdd = AliasSeq!(Arr[0]); 26 } else { 27 alias removeOdd = Arr; 28 } 29 } 30 31 unittest { 32 static assert(is(removeOdd!(int, float) == AliasSeq!(int))); 33 static assert(is(removeOdd!(int, float, long) == AliasSeq!(int, long))); 34 } 35 36 template getType(alias T) { 37 alias getType = typeof(T); 38 } 39 40 unittest { 41 static assert(is(getType!(6) == int)); 42 } 43 44 string[] getBasicVariablesFullNames(T)(string begin) { 45 string[] fullNames; 46 47 alias fields = Fields!T; 48 alias names = FieldNameTuple!T; 49 foreach (i, name; names) { 50 static if (is(fields[i] == struct)) { 51 fullNames ~= getBasicVariablesFullNames!(fields[i])(begin ~ "." ~ name); 52 } else { 53 fullNames ~= begin ~ "." ~ name; 54 } 55 } 56 return fullNames; 57 }