Summary: countUntil chokes on reference ranges
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from 2012-10-14 13:43:47 PDT ---

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()
    bool empty()
        return _p.s.empty;

void main()
    auto s = Forward("abc");
    auto s1 = Forward("ac");


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.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to