Bug 9160 – 2.061alpha multiSort no longer working with L-value only comparators
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-15T06:01:00Z
Last change time
2012-12-16T18:29:36Z
Keywords
pull
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2012-12-15T06:01:52Z
Changing DMD to no longer accept struct literals as L-value as a side effect broke template constraint in std.algorithm.multiSort:
7556: is(typeof(binaryFun!(less[0])(E.init, E.init)) == bool)
The E.init is not an L-value and thus the code below no longer works:
import std.algorithm;
struct A{
int x;
int y;
//... potentially quite big struct
}
bool byX(const ref A lhs, const ref A rhs)
{
return lhs.x < rhs.x;
}
bool byY(const ref A lhs, const ref A rhs)
{
return lhs.y < rhs.y;
}
void main()
{
auto points = [ A(4, 1), A(2, 4)];
multiSort!(byX, byY)(points);
assert(points[0] == A(2, 4));
assert(points[1] == A(4, 1));
}
A chunk of text for this error:
multi_bug.d(22): Error: template std.algorithm.multiSort!(byX, byY).multiSort do
es not match any function template declaration. Candidates are:
C:\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(7712): std.algorithm
.multiSort!(byX, byY).multiSort(Range)(Range r) if (validPredicates!(ElementType
!(Range), less))
multi_bug.d(22): Error: template std.algorithm.multiSort!(byX, byY).multiSort(Ra
nge)(Range r) if (validPredicates!(ElementType!(Range), less)) cannot deduce tem
plate function from argument types !()(A[])