Bug 11422 – std.array.assocArray with const tuple values
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-11-02T16:07:04Z
Last change time
2017-08-31T11:39:19Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-11-02T16:07:04Z
I think both cases need to be accepted or both need to be refused:
import std.array: assocArray;
import std.range: zip;
import std.typecons: Tuple;
void main() {
auto keys = [10, 20, 30];
const vals1 = [1, 2, 3];
//keys.zip(vals1).assocArray; // OK
alias R = Tuple!int;
const vals2 = [R(1), R(2), R(3)];
keys.zip(vals2).assocArray; // Error
}
dmd 2.064beta4 gives:
...\dmd2\src\phobos\std\array.d(249): Error: template std.typecons.Tuple!int.Tuple.opAssign does not match any function template declaration. Candidates are:
...\dmd2\src\phobos\std\typecons.d(504): std.typecons.Tuple!int.Tuple.opAssign(R)(auto ref R rhs) if (areCompatibleTuples!(typeof(this), R, "="))
...\dmd2\src\phobos\std\array.d(249): Error: template std.typecons.Tuple!int.Tuple.opAssign(R)(auto ref R rhs) if (areCompatibleTuples!(typeof(this), R, "=")) cannot deduce template function from argument types !()(const(Tuple!int)) const
test.d(10): Error: template instance std.array.assocArray!(Zip!(int[], const(Tuple!int)[])) error instantiating
Comment #1 by razvan.nitu1305 — 2017-08-31T09:38:47Z
On git HEAD I get "Error: static assert "assocArray: value type must be mutable"", so this seems to have been fixed. Closing.
Comment #2 by razvan.nitu1305 — 2017-08-31T11:39:19Z
(In reply to RazvanN from comment #1)
> On git HEAD I get "Error: static assert "assocArray: value type must be
> mutable"", so this seems to have been fixed. Closing.
I meant for both calls of assocArray.