# HG changeset patch # User Jacob Carlborg # Date 1263126178 -3600 # Node ID c2fba45df857b7bdcad34d8dde1f16d3710bd61b # Parent 19885b43130eb94bbec7266bb47a0188446b716a Fixed: indexOf didn't compile diff -r 19885b43130e -r c2fba45df857 dstep/internal/Traits.d --- a/dstep/internal/Traits.d Sun Jan 03 22:06:11 2010 +0100 +++ b/dstep/internal/Traits.d Sun Jan 10 13:22:58 2010 +0100 @@ -107,19 +107,42 @@ */ private size_t indexOf (T) (T[] arr, T element) { - static if (is(T == char) || is(T == wchar) || is(T == dchar)) - foreach (i, dchar e ; arr) - if (e == element) - return i; - - else - foreach (i, e ; arr) - if (e == element) - return i; + foreach (i, e ; arr) + if (e == element) + return i; return size_t.max; } +//FIXME fix this when http://d.puremagic.com/issues/show_bug.cgi?id=3512 is fixed +version (none) +{ + +/** + * Compile-time function to get the index of the give element. + * + * Performs a linear scan, returning the index of the first occurrence + * of the specified element in the array, or U.max if the array does + * not contain the element. + * + * Params: + * arr = the array to get the index of the element from + * element = the element to find + * + * Returns: the index of the element or size_t.max if the element was not found. + */ +private size_t indexOf (T) (T[] arr, dchar element) +{ + static assert(is(T == char) || is(T == wchar) || is(T == dchar), `dstep.internal.Traits.indexOf: The given type "` ~ T.stringof ~ `" is not valid, it has to be char, wchar or dchar`); + + foreach (i, dchar e ; arr) + if (e == element) + return i; + + return size_t.max; +} +} + /** * Evaluates to true if $(D_PARAM T) has a instance method with the given name *