phobos
phobos copied to clipboard
Fix Issue 17634 - variadic overload of std.algorithm.searching.countUntil should return which needle was found
Thanks a lot to @MartinNowak for suggesting this solution on Slack.
CC @RazvanN7
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"
Awesome. Looks good to me.
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.