www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - unpacking

reply spir <denis.spir gmail.com> writes:
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
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
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
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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