let (x,y) = ...

Nick Treleaven via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Feb 19 05:52:27 PST 2015


On 19/02/2015 04:38, thedeemon wrote:
> int x, y, z, age;
> string name;
>
> let (name, age) = getTuple();           // tuple
> let (x,y,z) = argv[1..4].map!(to!int);  // lazy range
> let (x,y,z) = [1,2,3];                  // array
>
> SomeStruct s;
> let (s.a, s.b) = tuple(3, "piggies");

Alternatively std.typetuple.TypeTuple can be used instead of let:
http://forum.dlang.org/post/op.wa4vn6lgsqugbd@localhost

> If a range or array doesn't have enough elements, this thing will throw,
> and if it's not desired there's
> let (x,y,z)[] = ...
> variant that uses just the available data and keeps the rest variables
> unchanged.

With these functions you can skip certain elements:
http://forum.dlang.org/post/jjnmh2$27o5$1@digitalmars.com


More information about the Digitalmars-d-announce mailing list