# HG changeset patch # User Jacob Carlborg # Date 1277500069 -7200 # Node ID 32152d5fad4ba56526141d6caeca0a6f3849299d # Parent ae24aae69a3b618eedcd76843df4703748766a9b nameOfFieldAt fails poorly if position >= tuple.length diff -r ae24aae69a3b -r 32152d5fad4b orange/util/Reflection.d --- a/orange/util/Reflection.d Fri Jun 25 20:27:27 2010 +0200 +++ b/orange/util/Reflection.d Fri Jun 25 23:07:49 2010 +0200 @@ -258,7 +258,7 @@ } /** - * Evaluates to a string containing the name of the field at given position in the type given type. + * Evaluates to a string containing the name of the field at given position in the given type. * * Params: * T = the type of the class/struct @@ -266,6 +266,8 @@ */ template nameOfFieldAt (T, size_t position) { + 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, `"`)); + static if (T.tupleof[position].stringof.length > T.stringof.length + 3) const nameOfFieldAt = T.tupleof[position].stringof[1 + T.stringof.length + 2 .. $];