let

Unpacks forward ranges, input ranges, static arrays, dynamic arrays, tuples, and user-defined types (via deconstructor methods) into the specified variables.

let
(
Ts...
)
(
ref Ts locals
)

Examples

1 // unpack an array
2 auto nums = [ 1, 2, 3 ];
3 
4 int a, b, c;
5 let( a, b, c ) = nums; // access the array indices and assign them to the a, b, and c variables
6 
7 // unpack a struct with a built-in deconstructor
8 struct Point
9 {
10     immutable int x;
11     immutable int y;
12 
13     void deconstruct( int* x, int* y )
14     {
15         *x = this.x;
16         *y = this.y;
17     }
18 }
19 
20 auto pt = Point( 5, 6 );
21 int x, y;
22 let( x, y ) = pt; // call Point.deconstruct() with pointers to the x and y variables

Meta

Authors

Tony J. Hudgins