digitalmars.D.learn - unpacking
- spir (8/8) Dec 07 2010 Hello D people,
- bearophile (4/7) Dec 07 2010 Not yet, but I have asked this feature for tuples too and maybe someone ...
- Stewart Gordon (16/20) Dec 07 2010 import std.stdio;
Hello D people, Is there a way to unpack an array into local vars, as: auto x =3D [1,2,3]; a,b,c =3D x; Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Dec 07 2010
spir:Is there a way to unpack an array into local vars, as: auto x = [1,2,3]; a,b,c = x;Not yet, but I have asked this feature for tuples too and maybe someone has appreciated it. Bye, bearophile
Dec 07 2010
On 07/12/2010 17:29, spir wrote:Hello D people, Is there a way to unpack an array into local vars, as: auto x = [1,2,3]; a,b,c = x;import std.stdio; void unpack(A, T...)(out T vars, A data) { assert (vars.length == data.length); foreach (i, v; vars) { vars[i] = data[i]; } } void main() { auto x = [1,2,3]; int a, b, c; unpack(a, b, c, x); writefln("%d %d %d", a, b, c); } Stewart.
Dec 07 2010