I just added a useful function to Phobos: findSkip. Refer to
http://d-programming-language.org/cutting-edge/phobos/std_algorithm.html#findSkip
and
http://www.dsource.org/projects/phobos/changeset/2339
I'm unsure about the signature. Currently the function returns
Tuple!(R1, "balance", bool, "found"), i.e. the balance of the range
being searched and a Boolean telling whether or not the other range was
found. The Boolean is necessary because returning an empty range is
ambiguous - did you find the needle at the very end of the haystack, or
not at all?
I think a signature that's easier to use is:
bool findSkip(alias pred = "a == b", R1, R2)(ref R1 haystack, R2 needle);
i.e. the haystack is passed by reference and modified if the find was
successful. This is in keep with skipOver's signature, but not in keep
with find's signature.
Opinions?
Andrei