Bug 8821 – countUntil chokes on reference ranges

Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P5
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-14T13:43:00Z
Last change time
2015-06-09T05:15:21Z
Assigned to
monarchdodra
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2012-10-14T13:43:47Z
Example: //--- import std.algorithm; import std.stdio; import std.array; struct Forward { static struct P { string s; } P* _p; this(string si) { _p = new P(); _p.s = si; } @property dchar front() { return _p.s.front; } void popFront() { _p.s.popFront(); } bool empty() { return _p.s.empty; } } void main() { auto s = Forward("abc"); auto s1 = Forward("ac"); s.countUntil(s1).writeln(); } //--- Produces "1". ROOT CAUSE ANALYSIS: The "problem" is "startsWith", which will consume both its input (both haystack and needle). Here, the first call to start with will consume the "a" of both "abc" and "ac". countUntil will the pop the b off of "bc", and finally, call startsWith on "c" and "c". Recommend saving ranges before calling startsWith (if both are ranges), but a more efficient solution could be found. Assigning to self.
Comment #1 by monarchdodra — 2012-10-14T13:45:39Z
(In reply to comment #0) > Assigning to self. Assigning to self.
Comment #2 by monarchdodra — 2012-12-16T23:13:49Z
https://github.com/D-Programming-Language/phobos/pull/951 Fixed and verified by monarchdodra on 17 dec 2012. Still requires writing some unit tests, which I will do after findSplit is itself also fixed for reference ranges.