[Issue 19220] New: multiSort and SortedRange.groupBy do not play together
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 4 21:32:25 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19220
Issue ID: 19220
Summary: multiSort and SortedRange.groupBy do not play together
Product: D
Version: D2
Hardware: x86_64
OS: All
Status: NEW
Severity: major
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: mrjnewt at gmail.com
std.algorithm.multiSort returns a SortedRange which in turn has a groupBy
method. Usage of this method does not actually compile when sorting by more
than one predicate. Example repro (online here:
https://run.dlang.io/is/mQGAvD):
import std.stdio;
import std.algorithm;
void main()
{
auto records = [
Record(10, 10),
Record(12, 1),
Record(30, 12),
Record(10, 10),
];
{
// Works:
auto groups = records.multiSort!(`a.x < b.x`).groupBy;
writeln(groups);
}
{
// Doesn't work:
auto groups = records.multiSort!(`a.x < b.x`, `a.y < b.y`).groupBy;
writeln(groups);
}
}
struct Record
{
int x;
int y;
}
SortedRange.groupBy apparently delegates the work to chunkBy which chokes on
the predicate defined by multiSort:
/dlang/dmd-beta/linux/bin64/../../src/phobos/std/algorithm/iteration.d(1821):
Error: static assert: "chunkBy expects either a binary predicate or a unary
predicate on range elements of type: Record"
/dlang/dmd-beta/linux/bin64/../../src/phobos/std/algorithm/iteration.d(1896):
instantiated from here: ChunkByImplIsUnary!(__lambda1, Record[])
/dlang/dmd-beta/linux/bin64/../../src/phobos/std/algorithm/iteration.d(2110):
instantiated from here: ChunkByImpl!(__lambda1, Record[])
/dlang/dmd-beta/linux/bin64/../../src/phobos/std/range/package.d(10730):
instantiated from here: chunkBy!((a, b) => !predFun(a, b) && !predFun(b, a),
Record[])
onlineapp.d(21): instantiated from here: groupBy!()
Commenting out the "doesn't work" section demonstrates that multiSort's
predicate works fine as long there's a single original predicate.
--
More information about the Digitalmars-d-bugs
mailing list