changeset 17:c2fba45df857

Fixed: indexOf didn't compile
author Jacob Carlborg <doob@me.com>
date Sun, 10 Jan 2010 13:22:58 +0100
parents 19885b43130e
children b2693af5a569
files dstep/internal/Traits.d
diffstat 1 files changed, 32 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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
  *