Andrei Alexandrescu wrote:
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

I am not sure where findSkip is useful but can we assume that the caller is not interested in whether it was found or not?

If the callers are interested, they should have the option of calling find and skip separately. If they are always interested, then find and skip should not be merged together.

Ali

Reply via email to