D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7587 - reduce() of a const array of tuples too
Summary: reduce() of a const array of tuples too
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-02-25 10:09 UTC by bearophile_hugs
Modified: 2014-02-16 14:28 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-02-25 10:09:28 UTC
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 Peter Alexander 2014-01-26 08:57:39 UTC
This appears to have been fixed in 2.061 although I can't find exactly where.
Comment 2 Peter Alexander 2014-02-16 14:28:13 UTC
Changed to WORKSFORME so that it doesn't appear in the changelog for next update.