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
Comment #2 by github-bugzilla — 2014-04-25T22:30:44Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/3cd997aef2948d3ce43761dba0c9b3804cb38d69 Fix Issue 12633 - std.conv.to should support target fixed-sized arrays. https://github.com/D-Programming-Language/phobos/commit/e03879ce815df7fd4eb64fa6f5d95597ad661d77 Merge pull request #2118 from AndrejMitrovic/Fix12633 Issue 12633 - std.conv.to should support target fixed-sized arrays