Bug 7587 – reduce() of a const array of tuples too
Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-02-25T10:09:00Z
Last change time
2014-02-16T14:28:13Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-02-25T10:09:28Z
import std.algorithm, std.typecons;
int add1(int x, int y) {
return x + y;
}
alias Tuple!int T;
T add2(T x, T y) {
return T(x[0] + y[0]);
}
void main() {
T[] items1 = [T(0), T(1)];
const t0 = T(0);
immutable r1 = reduce!add2(t0, items1); // OK
const(int[]) items2 = [0, 1];
const int zero = 0;
immutable r2 = reduce!add1(zero, items2); // OK
const(T[]) items3 = items1.idup;
immutable r3 = reduce!add2(t0, items3); // Error
}
DMD 2.059head gives:
...\dmd2\src\phobos\std\typecons.d(399): Error: template std.typecons.Tuple!(int).Tuple.opAssign(R) if (isTuple!(R) && allSatisfy!(isIdentityAssignable,Types)) does not match any function template declaration
...\dmd2\src\phobos\std\typecons.d(399): Error: template std.typecons.Tuple!(int).Tuple.opAssign(R) if (isTuple!(R) && allSatisfy!(isIdentityAssignable,Types)) cannot deduce template function from argument types !()(const(int))
...\dmd2\src\phobos\std\algorithm.d(702): Error: template instance std.typecons.Tuple!(Tuple!(int)).Tuple.__ctor!(const(Tuple!(int))) error instantiating
test.d(17): instantiated from here: reduce!(const(Tuple!(int)),const(Tuple!(int)[]))
test.d(17): Error: template instance std.algorithm.reduce!(add2).reduce!(const(Tuple!(int)),const(Tuple!(int)[])) error instantiating
I think just as reduce works on an const(int[]) it should also work on an const(Tuple!(int)[]).
Comment #1 by peter.alexander.au — 2014-01-26T08:57:39Z
This appears to have been fixed in 2.061 although I can't find exactly where.
Comment #2 by peter.alexander.au — 2014-02-16T14:28:13Z
Changed to WORKSFORME so that it doesn't appear in the changelog for next update.