-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
33 lines (27 loc) · 689 Bytes
/
main.cpp
File metadata and controls
33 lines (27 loc) · 689 Bytes
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
#include <nth/scope.h>
#include <cstdio>
int main()
{
int i = 42;
nth::scope_exit_t on_exit_1 = [&] {
printf("on_exit_1: %d\n", i);
};
nth::scope_exit_t on_exit_2 = [] {
printf("on_exit_2\n");
};
nth::scope_fuse_t on_exit_3 = [] {
printf("on_exit_3\n");
};
nth::scope_fuse_t on_exit_4 = [] {
printf("on_exit_4\n");
};
on_exit_3.invoke(); // invoke before scope exit
// on_exit_3
on_exit_3.invoke(); // no-op
on_exit_3.defuse(); // no-op
on_exit_4.defuse(); // cancel before scope exit
// ~on_exit_4 won't be invoked
// ~on_exit_3 won't be invoked
// on_exit_2
// on_exit_1: 42
}