Bug 17634 – variadic overload of std.algorithm.searching.countUntil should return which needle was found

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-11T16:07:21Z
Last change time
2024-12-01T16:30:33Z
Keywords
pull
Assigned to
No Owner
Creator
Seb
Moved to GitHub: phobos#10257 →

Comments

Comment #0 by greensunny12 — 2017-07-11T16:07:21Z
Find does this already: https://dlang.org/phobos/std_algorithm_searching.html#.find.4 > A tuple containing haystack positioned to match one of the needles and also the 1-based index of the matching element in needles (0 if none of needles matched, 1 if needles[0] matched, 2 if needles[1] matched...). The first needle to be found will be the one that matches. If multiple needles are found at the same spot in the range, then the shortest one is the one which matches (if multiple needles of the same length are found at the same spot (e.g "a" and 'a'), then the left-most of them in the argument list matches). It would be convenient if countUntil would behave the same, but it's probably too late to change the return type, so the only way left is adding an optional `out` parameter.
Comment #1 by b2.temp — 2017-09-01T21:22:24Z
"dropExactly(c).startWith(...)" would allow to find the needle also we can imagine a struct-based return type that doesn't break the current code: struct countUntilResult() { ptrdiff_t pos; size_t index; }
Comment #2 by b2.temp — 2017-09-01T21:23:15Z
(In reply to b2.temp from comment #1) > "dropExactly(c).startWith(...)" would allow to find the needle > > also we can imagine a struct-based return type that doesn't break the > current code: > > struct countUntilResult() > { > ptrdiff_t pos; size_t index; > } Something like struct countUntilResult() { ptrdiff_t pos; size_t index; alias pos this; }
Comment #3 by dlang-bot — 2021-10-15T13:08:55Z
@wilzbach updated dlang/phobos pull request #5618 "Fix Issue 17634 - variadic overload of std.algorithm.searching.countUntil should return which needle was found" fixing this issue: - Fix Issue 17634 - variadic overload of std.algorithm.searching.countUntil should return which needle was found https://github.com/dlang/phobos/pull/5618
Comment #4 by robert.schadek — 2024-12-01T16:30:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10257 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB