comparison lphobos/std/traits.d @ 473:373489eeaf90

Applied downs' lphobos update
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 04 Aug 2008 19:28:49 +0200
parents 61615fa85940
children
comparison
equal deleted inserted replaced
472:15c804b6ce77 473:373489eeaf90
125 assert(TL.length == 2); 125 assert(TL.length == 2);
126 assert(is (TL[0] == A)); 126 assert(is (TL[0] == A));
127 assert(is (TL[1] == I)); 127 assert(is (TL[1] == I));
128 } 128 }
129 129
130 /* *******************************************
131 */
132 template isStaticArray_impl(T)
133 {
134 const T inst = void;
135
136 static if (is(typeof(T.length)))
137 {
138 static if (!is(typeof(T) == typeof(T.init)))
139 { // abuses the fact that int[5].init == int
140 static if (is(T == typeof(T[0])[inst.length]))
141 { // sanity check. this check alone isn't enough because dmd complains about dynamic arrays
142 const bool res = true;
143 }
144 else
145 const bool res = false;
146 }
147 else
148 const bool res = false;
149 }
150 else
151 {
152 const bool res = false;
153 }
154 }
155 /** 130 /**
156 * Detect whether type T is a static array. 131 * Detect whether type T is a static array.
157 */ 132 */
158 template isStaticArray(T) 133 template isStaticArray(T)
159 { 134 {
160 const bool isStaticArray = isStaticArray_impl!(T).res; 135 static if (isArray!(T))
136 const bool isStaticArray = !is(T == typeof(T[0])[]);
137 else const bool isStaticArray = false;
161 } 138 }
162 139
163 140
164 static assert (isStaticArray!(int[51])); 141 static assert (isStaticArray!(int[51]));
165 static assert (isStaticArray!(int[][2])); 142 static assert (isStaticArray!(int[][2]));