[Issue 18285] New: std.algorithm.comparison.cmp for strings with custom predicate erroneously compares lengths with pred
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jan 23 06:27:01 UTC 2018
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 at puremagic.com
Reporter: n8sh.secondary at 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"!`);
}
```
--
More information about the Digitalmars-d-bugs
mailing list