-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.cpp
More file actions
65 lines (49 loc) · 1.95 KB
/
Copy pathExample.cpp
File metadata and controls
65 lines (49 loc) · 1.95 KB
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
64
65
#include <_Log_.h>
#include <global_macro_functions.h>
#include <functional>
#include <vector>
using namespace std;
class StoresCoolBlocksOfCode {
vector<function<void()>> _codeBlocks;
vector<function<void(int, int)>> _codeBlocksWithArguments;
public:
void AddCodeBlock(function<void()> codeBlock) { _codeBlocks.push_back(codeBlock); }
void AddCodeBlockWithArguments(function<void(int, int)> codeBlock) {
_codeBlocksWithArguments.push_back(codeBlock);
}
void ExecuteAllCodeBlocks(int arg1 = 69, int arg2 = 420) {
for (auto codeBlock : _codeBlocks) codeBlock();
for (auto codeBlock : _codeBlocksWithArguments) codeBlock(arg1, arg2);
}
};
StoresCoolBlocksOfCode TheMainBlocksOfCode;
#define CoolBlockOfCode \
_GLOBAL_MACRO_FUNCTIONS_REGISTER_NEW_FUNCTION(TheMainBlocksOfCode.AddCodeBlock) \
()
// Global code blocks (with arguments)
CoolBlockOfCode { _Log_("Hello from FIRST CoolBlockOfCode!"); }
CoolBlockOfCode { _Log_("Hello from SECOND CoolBlockOfCode!"); }
#define BlockWithArguments \
_GLOBAL_MACRO_FUNCTIONS_REGISTER_NEW_FUNCTION_WITH_ARGUMENTS( \
TheMainBlocksOfCode.AddCodeBlockWithArguments, int, int \
)
// Global code blocks (with arguments)
BlockWithArguments(int arg1, int arg2) {
_Log_("Hello from BlockWithArguments! arg1 = {}, arg2 = {}", arg1, arg2);
}
// TODO
// // Pass along other arguments to the block registration function
// RegisterNamedBlock("Name One") {
// _Log_("Hello from NamedBlock! Name = {}", name);
// }
// RegisterNamedBlock("Name Two") {
// _Log_("Hello from NamedBlock! Name = {}", name);
// }
// And an arbitrary lambda that runs at the start of main
#define RunMe _GLOBAL_MACRO_FUNCTIONS_RUN()
RunMe { _Log_("Hello from RunMe!"); }
int main() {
_Log_("Hello from main!");
TheMainBlocksOfCode.ExecuteAllCodeBlocks();
return 0;
}