Mercurial > projects > orange
comparison orange/util/Reflection.d @ 7:32152d5fad4b
nameOfFieldAt fails poorly if position >= tuple.length
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 25 Jun 2010 23:07:49 +0200 |
parents | 11a31bd929f9 |
children | 99c52d46822a |
comparison
equal
deleted
inserted
replaced
6:ae24aae69a3b | 7:32152d5fad4b |
---|---|
256 else | 256 else |
257 alias TypeOfFieldImpl!(T, field, i + 1) TypeOfFieldImpl; | 257 alias TypeOfFieldImpl!(T, field, i + 1) TypeOfFieldImpl; |
258 } | 258 } |
259 | 259 |
260 /** | 260 /** |
261 * Evaluates to a string containing the name of the field at given position in the type given type. | 261 * Evaluates to a string containing the name of the field at given position in the given type. |
262 * | 262 * |
263 * Params: | 263 * Params: |
264 * T = the type of the class/struct | 264 * T = the type of the class/struct |
265 * position = the position of the field in the tupleof array | 265 * position = the position of the field in the tupleof array |
266 */ | 266 */ |
267 template nameOfFieldAt (T, size_t position) | 267 template nameOfFieldAt (T, size_t position) |
268 { | 268 { |
269 static assert (position < T.tupleof.length, format!(`The given position "`, position, `" is greater than the number of fields (`, T.tupleof.length, `) in the type "`, T, `"`)); | |
270 | |
269 static if (T.tupleof[position].stringof.length > T.stringof.length + 3) | 271 static if (T.tupleof[position].stringof.length > T.stringof.length + 3) |
270 const nameOfFieldAt = T.tupleof[position].stringof[1 + T.stringof.length + 2 .. $]; | 272 const nameOfFieldAt = T.tupleof[position].stringof[1 + T.stringof.length + 2 .. $]; |
271 | 273 |
272 else | 274 else |
273 const nameOfFieldAt = ""; | 275 const nameOfFieldAt = ""; |