Bug 18285 – std.algorithm.comparison.cmp for strings with custom predicate compares lengths wrong
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-23T06:27:01Z
Last change time
2018-01-26T21:21:14Z
Assigned to
No Owner
Creator
Nathan S.
Comments
Comment #0 by n8sh.secondary — 2018-01-23T06:27:01Z
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"!`);
}
```
Comment #1 by n8sh.secondary — 2018-01-26T21:21:14Z