First commit
[cpp_sandbox.git] / Sandbox / main.cpp
1 #include <iostream>
2 #include <vector>
3 #include <list>
4 #include <chrono>
5 using namespace std;
6
7 #include "DefaultMethods.h"
8 #include "Traits.h"
9 #include "PointerToMember.h"
10 #include "FunctionsAsTemplate.h"
11 #include "CostOfUsingStatic.h"
12 #include "TemplateMetaProgramming.h"
13 #include "NextAndExchange.h"
14 #include "Bind.h"
15 #include "ConstexprIf.h"
16 #include "FoldExpressions.h"
17 #include "IfAndSwitchInitStatements.h"
18 #include "AggregateInitializations.h"
19 #include "VariadicUsing.h"
20 #include "VariadicTemplates.h"
21 #include "Lambdas.h"
22 #include "ReadVarint.h"
23 #include "Concepts.h"
24
25 constexpr auto DEFAULT_METHODS_ENABLED = false;
26 constexpr auto TRAITS_ENABLED = false;
27 constexpr auto POINTER_TO_MEMBER = false;
28 constexpr auto FUNCTIONS_AS_TEMPLATE = false;
29 constexpr auto COST_OF_USING_STATIC = false;
30 constexpr auto TEMPLATE_METAPROGRAMMING = false;
31 constexpr auto NEXT_AND_EXCHANGE = false;
32 constexpr auto BIND = false;
33 constexpr auto CONSTEXPR_IF = false;
34 constexpr auto FOLD_EXPRESSIONS = false;
35 constexpr auto IF_AND_SWITCH_INIT_STATEMENTS = false;
36 constexpr auto AGGREGATE_INITIALIZATIONS = false;
37 constexpr auto VARIADIC_USING = false;
38 constexpr auto VARIADIC_TEMPLATES = false;
39 constexpr auto LAMBDAS = false;
40 constexpr auto READ_VARINT = false;
41 constexpr auto CONCEPTS = true;
42
43 bool isLucky(int n)
44 {
45 return n == 13;
46 }
47
48 // Forbid to be called with char or float (automatic conversion to 'int').
49 bool isLucky(char) = delete;
50 bool isLucky(double) = delete;
51
52 struct Pod
53 {
54 int a;
55 double b;
56 };
57
58 int main()
59 {
60 // Do not forget that 'endl' call 'flush' as well. Never use 'endl' when writing a lot of data (into a file for example).
61 cout << "Sandbox C++" << endl;
62 cout << "-----------" << endl;
63
64 auto startTime = chrono::steady_clock::now();
65
66 if constexpr (DEFAULT_METHODS_ENABLED)
67 DefaultMethods::tests();
68
69 if constexpr (TRAITS_ENABLED)
70 Traits::tests();
71
72 if constexpr (POINTER_TO_MEMBER)
73 PointerToMember::tests();
74
75 if constexpr (FUNCTIONS_AS_TEMPLATE)
76 FunctionsAsTemplate::tests();
77
78 if constexpr (COST_OF_USING_STATIC)
79 CostOfUsingStatic::tests();
80
81 if constexpr (TEMPLATE_METAPROGRAMMING)
82 TemplateMetaProgramming::tests();
83
84 if constexpr (NEXT_AND_EXCHANGE)
85 NextAndExchange::tests();
86
87 if constexpr (BIND)
88 Bind::tests();
89
90 if constexpr (CONSTEXPR_IF)
91 ConstexprIf::tests();
92
93 if constexpr (FOLD_EXPRESSIONS)
94 FoldExpressions::tests();
95
96 if constexpr (IF_AND_SWITCH_INIT_STATEMENTS)
97 IfAndSwitchInitStatements::tests();
98
99 if constexpr (AGGREGATE_INITIALIZATIONS)
100 AggregateInitializations::tests();
101
102 if constexpr (VARIADIC_USING)
103 VariadicUsing::tests();
104
105 if constexpr (VARIADIC_TEMPLATES)
106 VariadicTemplates::tests();
107
108 if constexpr (LAMBDAS)
109 Lambdas::tests();
110
111 if constexpr (READ_VARINT)
112 ReadVarint::tests();
113
114 if constexpr (CONCEPTS)
115 Concepts::tests();
116
117 auto endTime = chrono::steady_clock::now();
118
119 cout << "-----------" << endl;
120 cout << "Elapsed time: " << chrono::duration_cast<chrono::milliseconds>(endTime - startTime).count() << " ms" << endl;
121
122 /*
123 cout << "Press ENTER to quit" << endl;
124 cin.ignore();
125 */
126 }