On 4/28/12 3:51 AM, Brad Anderson wrote:
On Friday, 27 April 2012 at 19:49:33 UTC, M.Gore wrote:
I'd like to know if there's a generic function over arrays to find the
index of a specific elemnt therein, something like, say:
int indexOf(S) (in S[] arr, S elem);
which works the same way the std.string.indexOf() function works...
couldn't find anything in the std.array module for this scenario.
Would be nice to have this functionality built-in somehow.
Or is there a completely different / better approach to this in D?
Thx, M.
countUntil in std.algorithm should work fine.
http://dlang.org/phobos/std_algorithm.html#countUntil
Regards,
Brad Anderson
---
sizediff_t indexOf(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle);
Scheduled for deprecation. Please use std.algorithm.countUntil instead.
Same as countUntil. This symbol has been scheduled for deprecation
because it is easily confused with the homonym function in std.string.
---
But isn't it the same funcionality? Why use a different name for the
same funcionality?