-
Notifications
You must be signed in to change notification settings - Fork 73
/
choice4.cxx
32 lines (26 loc) · 1.01 KB
/
choice4.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#feature on choice tuple new_decl_syntax
#include <tuple>
#include <iostream>
struct obj_t {
var a : (int, int); // A 2-tuple.
var b : (std::string, double, int); // A 3-tuple.
}
fn func(arg : auto) {
match(arg) {
// Destructure the a member and test if it's (10, 20)
[a: (10, 20)] => std::cout<< "The 'a' member is (10, 20).\n";
// Check the range of the double tuple element.
[_, [_, 1...100, _] ] => std::cout<< "The double is between 1 and 100\n";
// a's 2nd element matches b's third element.
[ [_, var x], [_, _, x] ] => std::cout<< "A magical coincidence.\n";
// Everything else goes here.
_ => std::cout<< "A rubbish struct.\n";
};
}
fn main() -> int {
func(obj_t { { 10, 20 }, { "Hello", 3, 4 } });
func(obj_t { { 2, 4 }, { "Hello", 3, 4 } });
func(obj_t { { 2, 5 }, { "Hello", 19.0, 4 } });
func(obj_t { { 2, 5 }, { "Hello", 101.0, 5 } });
func(obj_t { { 2, 5 }, { "Hello", 101.0, 6 } });
}