source: doc/theses/jiada_liang_MMath/test.cc@ 56ec508

Last change on this file since 56ec508 was 7568e5c, checked in by JiadaL <j82liang@…>, 13 months ago

Minor update on the thesis (add auto initialization and update future work

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#include <iostream>
2#include <cstdlib>
3#include <variant>
4using 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
28constexpr auto one = 0 + 1;
29const auto NUL = nullptr;
30const auto PI = 3.14159;
31const auto Plus = '+';
32const auto Fred = "Fred";
33const auto Mon = 0, Tue = Mon + 1, Wed = Tue + 1, Thu = Wed + 1, Fri = Thu + 1, Sat = Fri + 1, Sun = Sat + 1;
34const auto r = random();
35
36enum E { A, B, C };
37enum class EC : long { A, B, C };
38
39int a1[Sun + 1], a2[C + 1];
40
41int 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: //
Note: See TracBrowser for help on using the repository browser.