1 /** 2 * This module is contains utility templates used by the other modules in 3 * $(CALIB_ABSTRACT). 4 * 5 * Take a look the various modules in $(CALIB_ABSTRACT) for usage examples. 6 */ 7 8 module caLib_abstract.util; 9 10 11 12 template hasCellStateType(T) 13 { 14 enum hasCellStateType = 15 is(T.CellStateType) && 16 is(T.init.CellStateType); 17 } 18 19 unittest 20 { 21 struct Foo { 22 alias CellStateType = void; 23 } 24 25 static assert( hasCellStateType!Foo); 26 static assert(!hasDimension!string); 27 } 28 29 30 31 template isCellStateTypesCompatible(T...) 32 { 33 static assert(T.length != 0); 34 35 static if(T.length == 1) 36 { 37 enum isCellStateTypesCompatible = true; 38 } 39 else 40 { 41 enum isCellStateTypesCompatible = 42 __traits(compiles, (() { 43 static assert(is(T[0] : T[1])); 44 })() ) && 45 isDimensionsCompatible!(T[1..$]); 46 } 47 } 48 49 unittest 50 { 51 static assert( isCellStateTypesCompatible!(int)); 52 static assert( isCellStateTypesCompatible!(int, uint)); 53 static assert(!isCellStateTypesCompatible!(int, string)); 54 } 55 56 57 58 template hasDisplayValueType(T) 59 { 60 enum hasDisplayValueType = 61 is(T.DisplayValueType) && 62 is(T.init.DisplayValueType); 63 } 64 65 66 67 template isDisplayValueTypesCompatible(T...) 68 { 69 static assert(T.length != 0); 70 71 static if(T.length == 1) 72 { 73 enum isCellStateTypesCompatible = true; 74 } 75 else 76 { 77 enum isCellStateTypesCompatible = 78 __traits(compiles, (() { 79 static assert(is(T[0] : T[1])); 80 })() ) && 81 isDimensionsCompatible!(T[1..$]); 82 } 83 } 84 85 unittest 86 { 87 static assert( isCellStateTypesCompatible!(int)); 88 static assert( isCellStateTypesCompatible!(int, uint)); 89 static assert(!isCellStateTypesCompatible!(int, string)); 90 } 91 92 93 94 template hasDimension(T) 95 { 96 enum hasDimension = 97 is(typeof(T.Dimension) : int) && 98 is(typeof(T.init.Dimension) : int); 99 } 100 101 unittest 102 { 103 struct Foo { 104 static immutable int Dimension = 0; 105 } 106 107 static assert( hasDimension!Foo); 108 static assert(!hasDimension!int); 109 } 110 111 112 113 template isDimensionsCompatible(T...) 114 { 115 static assert(T.length != 0); 116 117 static if(T.length == 1) 118 { 119 enum isDimensionsCompatible = true; 120 } 121 else 122 { 123 enum isDimensionsCompatible = 124 __traits(compiles, (() { 125 static assert(T[0] == T[1]); 126 })() ) && 127 isDimensionsCompatible!(T[1..$]); 128 129 } 130 } 131 132 unittest 133 { 134 static assert( isDimensionsCompatible!(0)); 135 static assert( isDimensionsCompatible!(0, 0u)); 136 static assert( isDimensionsCompatible!(0, 0u, byte(0))); 137 static assert(!isDimensionsCompatible!(0, 0.1f)); 138 } 139 140 141 142 template hasNeighbourhoodType(T) 143 { 144 enum hasNeighbourhoodType = 145 is(T.NeighbourhoodType) && 146 is(T.init.NeighbourhoodType); 147 } 148 149 unittest 150 { 151 pragma(msg, "no unittest for template hasNeighbourhood in util.d"); 152 }