phobos icon indicating copy to clipboard operation
phobos copied to clipboard

Fix Issue 17634 - variadic overload of std.algorithm.searching.countUntil should return which needle was found

Open wilzbach opened this issue 6 years ago • 3 comments

Thanks a lot to @MartinNowak for suggesting this solution on Slack.

CC @RazvanN7

wilzbach avatar Jul 16 '17 21:07 wilzbach

Thanks for your pull request, @wilzbach!

Bugzilla references

Auto-close Bugzilla Severity Description
8804 minor countUntil warning on an infinite range
17634 enhancement variadic overload of std.algorithm.searching.countUntil should return which needle was found

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#5618"

dlang-bot avatar Jul 16 '17 21:07 dlang-bot

Awesome. Looks good to me.

RazvanN7 avatar Jul 17 '17 08:07 RazvanN7

Regardless, this is liable to break code - what with people using auto and all.

Yes in theory that's possible, but isn't this unlikely as the resulting type will behave as if it would be a ptrdiff_t?

How about just adding a new function countUntilWhich that takes a ref size_t as its second argument?

I would like to avoid introducing a new symbol for this seldom use-case. Hence, if we can't do the trick above, I think a template flag would be better e.g. countUntil!Yes.needleCount(haystack, needles). Also note that countUntil(haystack, needlePosition, needles) would be possible as well.

wilzbach avatar Jul 17 '17 23:07 wilzbach