-
Notifications
You must be signed in to change notification settings - Fork 0
/
Second.cpp
63 lines (44 loc) · 1.54 KB
/
Second.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <variant>
#include <tuple>
#include <cstdio>
#include "mpark/patterns.hpp"
using namespace std;
using namespace mpark::patterns;
using str = std::string;
template <typename T>
void println(T var) { cout << var << endl; }
class lit : public string {};
variant<tuple<str, int>, tuple<str, str>> giveVariant2(int in)
{
if (in == 1) return make_tuple("ok", 10);
if (in == 2) return make_tuple("ok", 88);
else return make_tuple("error", "unexpected_int");
}
variant<int, str> giveVariant3(int in)
{
if (in == 1) return "ok";
if (in == 2) return 88;
else return "error";
}
variant<int, tuple<str, int>> giveVariant4(int in)
{
if (in == 1) return make_tuple("ok", 10);
if (in == 2) return make_tuple("ok", 88);
else return 0;
}
int main()
{
variant<tuple<str, int>, tuple<str, str>> myVari = giveVariant2(1);
variant<tuple<int, str>, tuple<str, str>, int, tuple<int, str, str>> varTuple = 54;
int test10 = 10;
tuple<int, str> test11 = make_tuple(10, "ok");
match (varTuple)
(
pattern(as<tuple<int, str>>(ds(arg, arg))) = [](int i, str s) { cout << "int, str: " << i << " - " << s << "\n"; },
pattern(as<tuple<str, str>>(ds(arg, arg))) = [](str s1, str s2) { cout << "str, str: " << s1 << " - " << s2 << "\n"; },
pattern(as<int>(arg)) = [](int x) { cout << "int: " << x << "\n"; },
pattern(as<tuple<int, str, str>>(ds(arg, arg, arg))) = [](int i, str s1, str s2) { cout << "Yolo"; }
);
return 0;
}