[33a7b6d] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // tupleAssign.c -- |
---|
| 8 | // |
---|
| 9 | // Author : Rob Schluntz |
---|
| 10 | // Created On : Tue Nov 15 17:24:32 2016 |
---|
[7fe2498] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Mon Mar 6 21:23:58 2017 |
---|
| 13 | // Update Count : 34 |
---|
[33a7b6d] | 14 | // |
---|
| 15 | |
---|
[7fe2498] | 16 | #include <fstream> |
---|
| 17 | |
---|
[a29be37] | 18 | int main() { |
---|
| 19 | { |
---|
| 20 | // test multiple assignment and cascading assignment |
---|
| 21 | int u = 5, v = 6, x = 10, y = 11; |
---|
| 22 | [int, int] z = [100, 200]; |
---|
| 23 | |
---|
| 24 | // swap x, y and store the new [x, y] in [u, v] and in z; |
---|
[7fe2498] | 25 | printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z ); |
---|
| 26 | sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]" | endl; |
---|
[a29be37] | 27 | z = [u, v] = [x, y] = [y, x]; |
---|
[7fe2498] | 28 | printf( "u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z ); |
---|
| 29 | sout | "u=" | u | "v=" | v | "x=" | x | "y=" | y | "z=[" | z | "]" | endl; |
---|
[a29be37] | 30 | |
---|
| 31 | // shuffle elements -- v = z.0, z.0 = z.1, z.1 = u, u = v |
---|
| 32 | [v, z, u] = [z, u, v]; |
---|
[7fe2498] | 33 | printf( "u=%d v=%d z=[%d, %d]\n", u, v, z ); |
---|
| 34 | sout | "u=" | u | "v=" | v | "z=[" | z | "]" | endl; |
---|
[a29be37] | 35 | |
---|
| 36 | // multiple assignment with tuple expression on right |
---|
| 37 | z = [111, 222]; |
---|
| 38 | [u, v] = [123, 456]; |
---|
[7fe2498] | 39 | printf( "u=%d v=%d z=[%d, %d]\n", u, v, z ); |
---|
| 40 | sout | "u=" | u | "v=" | v | "z=[" | z | "]" | endl; |
---|
[a29be37] | 41 | } |
---|
| 42 | { |
---|
| 43 | // test mass assignment |
---|
| 44 | double d = 0.0; |
---|
| 45 | int i = 0; |
---|
| 46 | char c = '\0'; |
---|
| 47 | struct X { |
---|
| 48 | int z; |
---|
| 49 | } x; |
---|
[2afec66] | 50 | X ?=?(X & x, double d) {} |
---|
[a29be37] | 51 | [int, double, int] t; |
---|
| 52 | |
---|
| 53 | // no conversion from X to integral types, so this serves as a santiy |
---|
| 54 | // check that as long as this compiles, ?=?(_, x) is not generated. |
---|
[7fe2498] | 55 | [t, x, d, i, c, x] = (double)94.12; |
---|
| 56 | printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, (int)c, t ); |
---|
| 57 | sout | "d=" | d | "i=" | i | "c=" | c | ' ' | "t=[" | t | "]" | endl; |
---|
| 58 | [x, c, i, d, x, t] = (double)-94.12; |
---|
| 59 | printf( "d=%lg i=%d c=%c t=[%d, %lg, %d]\n", d, i, c, t ); |
---|
| 60 | sout | "d=" | d | "i=" | i | "c=" | c | ' ' | "t=[" | t | "]" | endl; |
---|
[a29be37] | 61 | } |
---|
| 62 | } |
---|
[33a7b6d] | 63 | |
---|
| 64 | // Local Variables: // |
---|
| 65 | // tab-width: 4 // |
---|
| 66 | // End: // |
---|