Bug 12633 – std.conv.to should support target fixed-sized arrays
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-24T13:18:00Z
Last change time
2014-04-25T22:30:45Z
Keywords
pull, rejects-valid
Assigned to
andrej.mitrovich
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-04-24T13:18:47Z
I think this should work:
void main() {
import std.conv: to;
const s2 = ["10", "20"];
immutable int[] a1 = s2.to!(int[]); // OK.
assert(a1.length == 2);
immutable int[] a2 = s2.to!(int[2]); // Error.
immutable int[2] a3 = s2.to!(int[2]); // Error.
}
DMD 2.065 gives:
...\dmd2\windows\bin\..\..\src\phobos\std\conv.d(1398): Error: cannot implicitly convert expression (w.data()) of type int[] to int[2]
[more errors]
It's useful when you read pairs of numbers from a file, to be sure every line has two of them.
And in theory the creation of the a3 array could even be @nogc.
Comment #1 by andrej.mitrovich — 2014-04-24T14:28:00Z