www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12633] New: std.conv.to for fixed-size arrays too


          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 puremagic.com
          Reporter: bearophile_hugs 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.

Apr 24 2014