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 | // tuplePolymorphism.c -- |
---|
8 | // |
---|
9 | // Author : Rob Schluntz |
---|
10 | // Created On : Tue Nov 16 10:38:00 2016 |
---|
11 | // Last Modified By : Rob Schluntz |
---|
12 | // Last Modified On : Tue Nov 16 10:39:18 2016 |
---|
13 | // Update Count : 2 |
---|
14 | // |
---|
15 | |
---|
16 | forall(otype T | { T ?+?(T, T); }) |
---|
17 | [T, T, T] ?+?([T, T, T] x, [T, T, T] y) { |
---|
18 | return [x.0+y.0, x.1+y.1, x.2+y.2]; |
---|
19 | } |
---|
20 | |
---|
21 | int main() { |
---|
22 | int x1 = 123, x3 = 456; |
---|
23 | double x2 = 999.123; |
---|
24 | |
---|
25 | int i1 = 111, i3 = 222; |
---|
26 | double i2 = 333; |
---|
27 | |
---|
28 | int d1 = 555, d3 = 444; |
---|
29 | double d2 = 666; |
---|
30 | |
---|
31 | |
---|
32 | [i1, i2, i3] = ([x1, (int)x2, x3]) + ([9, 2, 3]); |
---|
33 | [d1, d2, d3] = ([x1, x2, x3]) + ([9, 2, 3]); |
---|
34 | printf("%d %g %d\n", i1, i2, i3); |
---|
35 | printf("%d %g %d\n", d1, d2, d3); |
---|
36 | |
---|
37 | [double, double, double] zzz; |
---|
38 | zzz = [x1, x2, x3]; |
---|
39 | printf("%g %g %g\n", zzz); |
---|
40 | [x1, x2, x3] = zzz+zzz; |
---|
41 | printf("%d %g %d\n", x1, x2, x3); |
---|
42 | } |
---|
43 | |
---|
44 | forall(otype T) |
---|
45 | [T, T] foo([T, T] y) { |
---|
46 | [T, T] x; |
---|
47 | return x; |
---|
48 | } |
---|
49 | |
---|
50 | // Local Variables: // |
---|
51 | // tab-width: 4 // |
---|
52 | // End: // |
---|
53 | |
---|