[Issue 7992] New: std.algorithm.find breaks in certain circumstances

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 26 14:56:32 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7992

           Summary: std.algorithm.find breaks in certain circumstances
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: nyphbl8d at gmail.com


--- Comment #0 from William Moore <nyphbl8d at gmail.com> 2012-04-26 14:57:31 PDT ---
When std.algorithm.find is used with a type that forces it to use
simpleMindedFind and the type in question supports the length attribute,
simpleMindedFind will throw an assert if the string to be searched does not
contain the search string.

For example:
struct omgstring {
        string data;
        // Start hasLength functions
        @property {
                size_t length() const {return data.length;}
                void length(size_t len) {data.length = len;}
        }
        // End hasLength functions

        // Start InputRange functions
        bool empty() const {return data.empty();}
        dchar front() const {return data.front();}
        void popFront() {data.popFront();}
        // End InputRange functions

        // Start ForwardRange functions (implies InputRange)
        mycustring save() {return this;}
        // End ForwardRange functions
}

// succeeds
simpleMindedFind!"a == b"("a","b");
// throws assert when it pops past the last element
simpleMindedFind!"a == b"(to!omgstring("a"),to!omgstring("b"));

Note that I'm not actually calling simpleMindedFind directly, but that is the
function the code ends up in when throwing the assert.  The code executes
correctly if the length property is removed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list