[Issue 18286] New: std.algorithm.comparison.cmp for string with custom predicate fails if distinct chars can compare equal

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 23 07:35:39 UTC 2018


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

          Issue ID: 18286
           Summary: std.algorithm.comparison.cmp for string with custom
                    predicate fails if distinct chars can compare equal
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: n8sh.secondary at hotmail.com

Discussion:
https://github.com/dlang/phobos/pull/6056#issuecomment-359701089

Example:
https://run.dlang.io/is/feq4KK

```
void main()
{
    import std.algorithm.comparison : cmp;
    static bool lessThanCaseInsensitive(size_t a, size_t b)
    {
        import std.ascii : toUpper;
        return toUpper(cast(dchar) a) < toUpper(cast(dchar) b);
    }
    static assert(cmp!lessThanCaseInsensitive("apple2", "APPLE1") != 0,
                 "These are clearly not the same!");
}
```

--


More information about the Digitalmars-d-bugs mailing list