1 | #include <iostream> |
---|
2 | #include <cstdlib> |
---|
3 | #include <variant> |
---|
4 | using namespace std; |
---|
5 | |
---|
6 | // struct S { char s[32]; }; |
---|
7 | // variant< int, double, S > vd; |
---|
8 | // variant< int, int, int > vs; |
---|
9 | |
---|
10 | // int main() { |
---|
11 | // cout << "sizeof vd " << sizeof( vd ) << endl; |
---|
12 | // vd = 3; |
---|
13 | // if ( holds_alternative<int>(vd) ) cout << "int " << get<int>(vd ) << endl; |
---|
14 | // vd = 3.5; |
---|
15 | // if ( holds_alternative<double>(vd) ) cout << "double " << get<double>(vd) << endl; |
---|
16 | // vd = (S){ "abc" }; |
---|
17 | // if ( holds_alternative<S>(vd) ) cout << "S.s " << get<S>(vd).s << endl; |
---|
18 | |
---|
19 | // cout << "sizeof vs " << sizeof( vs ) << endl; |
---|
20 | // vs = (variant<int,int,int>){ in_place_index<0>, 12 }; |
---|
21 | // if ( vs.index() == 0 ) cout << "posn 0 " << get<0>(vs) << endl; |
---|
22 | // vs = (variant<int,int,int>){ in_place_index<1>, 4 }; |
---|
23 | // if ( vs.index() == 1 ) cout << "posn 1 " << get<1>(vs) << endl; |
---|
24 | // vs = (variant<int,int,int>){ in_place_index<2>, 5 }; |
---|
25 | // if ( vs.index() == 2 ) cout << "posn 2 " << get<2>(vs) << endl; |
---|
26 | // } |
---|
27 | |
---|
28 | constexpr auto one = 0 + 1; |
---|
29 | const auto NUL = nullptr; |
---|
30 | const auto PI = 3.14159; |
---|
31 | const auto Plus = '+'; |
---|
32 | const auto Fred = "Fred"; |
---|
33 | const auto Mon = 0, Tue = Mon + 1, Wed = Tue + 1, Thu = Wed + 1, Fri = Thu + 1, Sat = Fri + 1, Sun = Sat + 1; |
---|
34 | const auto r = random(); |
---|
35 | |
---|
36 | enum E { A, B, C }; |
---|
37 | enum class EC : long { A, B, C }; |
---|
38 | |
---|
39 | int a1[Sun + 1], a2[C + 1]; |
---|
40 | |
---|
41 | int main() { |
---|
42 | const auto one = random(); |
---|
43 | // const int * ip = &one; |
---|
44 | int sa[Sun]; |
---|
45 | int * i = NUL; |
---|
46 | E e; |
---|
47 | // switch ( e ) { |
---|
48 | // case w: ; |
---|
49 | // } |
---|
50 | switch ( e ) { |
---|
51 | case Sat: ; |
---|
52 | } |
---|
53 | switch ( e ) { |
---|
54 | case C: ; |
---|
55 | } |
---|
56 | EC ec; |
---|
57 | switch ( ec ) { |
---|
58 | case EC::A: ; |
---|
59 | } |
---|
60 | EC eca[C]; |
---|
61 | eca[A] = EC::A; |
---|
62 | |
---|
63 | enum Week { Mon, Tue, Wed, Thu = 10, Fri, Sat = 8, Sun }; |
---|
64 | if ( Fri < Sat ) cout << "hmm" << endl; |
---|
65 | else cout << "ahh" << std::endl; |
---|
66 | Week day = Mon; |
---|
67 | if ( day <= Fri ) cout << "weekday" << endl; |
---|
68 | switch ( day ) { |
---|
69 | case Mon: case Tue: case Wed: case Thu: case Fri: |
---|
70 | cout << "weekday" << endl; break; |
---|
71 | case Sat: case Sun: |
---|
72 | cout << "weekend" << endl; break; |
---|
73 | } |
---|
74 | for ( Week d = Mon; d <= Sun; d = (Week)(d + 1) ) { |
---|
75 | cout << d << ' '; |
---|
76 | } |
---|
77 | cout << endl; |
---|
78 | } |
---|
79 | |
---|
80 | // Local Variables: // |
---|
81 | // compile-command: "g++ -std=c++17 test.cc" // |
---|
82 | // End: // |
---|