[Issue 12633] New: std.conv.to for fixed-size arrays too
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Apr 24 06:18:47 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12633
Issue ID: 12633
Summary: std.conv.to for fixed-size arrays too
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: rejects-valid
Severity: enhancement
Priority: P1
Component: Phobos
Assignee: nobody at puremagic.com
Reporter: bearophile_hugs at eml.cc
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.
--
More information about the Digitalmars-d-bugs
mailing list