www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18285] New: std.algorithm.comparison.cmp for strings with

https://issues.dlang.org/show_bug.cgi?id=18285

          Issue ID: 18285
           Summary: std.algorithm.comparison.cmp for strings with custom
                    predicate erroneously compares lengths with pred
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

Discussion:
https://github.com/dlang/phobos/pull/6056#pullrequestreview-90703862

Sample code demonstrating bug:
https://run.dlang.io/is/RJnPBw
```
void main()
{
    import std.algorithm.comparison : cmp;
    // Note that "a > b" is the reverse of the normal.
    static assert(cmp!"a > b"("1", "2") > 0);
    // Following fails because cmp is using the predicate "a > b"    
    // to compare the lengths of the ranges.    
    static assert(cmp!"a > b"("abc", "abcd") < 0,
                 `Should be negative because "abc" is a prefix of "abcd"!`);
}
```

--
Jan 22 2018