Mercurial > projects > dstep
comparison dstep/internal/Traits.d @ 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 |
comparison
equal
deleted
inserted
replaced
16:19885b43130e | 17:c2fba45df857 |
---|---|
105 * | 105 * |
106 * Returns: the index of the element or size_t.max if the element was not found. | 106 * Returns: the index of the element or size_t.max if the element was not found. |
107 */ | 107 */ |
108 private size_t indexOf (T) (T[] arr, T element) | 108 private size_t indexOf (T) (T[] arr, T element) |
109 { | 109 { |
110 static if (is(T == char) || is(T == wchar) || is(T == dchar)) | 110 foreach (i, e ; arr) |
111 foreach (i, dchar e ; arr) | 111 if (e == element) |
112 if (e == element) | 112 return i; |
113 return i; | |
114 | |
115 else | |
116 foreach (i, e ; arr) | |
117 if (e == element) | |
118 return i; | |
119 | 113 |
120 return size_t.max; | 114 return size_t.max; |
115 } | |
116 | |
117 //FIXME fix this when http://d.puremagic.com/issues/show_bug.cgi?id=3512 is fixed | |
118 version (none) | |
119 { | |
120 | |
121 /** | |
122 * Compile-time function to get the index of the give element. | |
123 * | |
124 * Performs a linear scan, returning the index of the first occurrence | |
125 * of the specified element in the array, or U.max if the array does | |
126 * not contain the element. | |
127 * | |
128 * Params: | |
129 * arr = the array to get the index of the element from | |
130 * element = the element to find | |
131 * | |
132 * Returns: the index of the element or size_t.max if the element was not found. | |
133 */ | |
134 private size_t indexOf (T) (T[] arr, dchar element) | |
135 { | |
136 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`); | |
137 | |
138 foreach (i, dchar e ; arr) | |
139 if (e == element) | |
140 return i; | |
141 | |
142 return size_t.max; | |
143 } | |
121 } | 144 } |
122 | 145 |
123 /** | 146 /** |
124 * Evaluates to true if $(D_PARAM T) has a instance method with the given name | 147 * Evaluates to true if $(D_PARAM T) has a instance method with the given name |
125 * | 148 * |