|
13 | 13 | // construct noisy |
14 | 14 | // --> scope end |
15 | 15 | // destroy noisy |
16 | | -// scope exit: true success: true fail: false |
| 16 | +// scope exit: true success: true fail: false |
17 | 17 |
|
18 | 18 | import std; |
19 | 19 | import beman.scope; |
20 | 20 |
|
21 | | -struct noisy_resource |
22 | | -{ |
23 | | - noisy_resource() { std::print("construct noisy\n"); } |
24 | | - ~noisy_resource() { std::print("destroy noisy\n"); } |
| 21 | +struct noisy_resource { |
| 22 | + noisy_resource() { std::print("construct noisy\n"); } |
| 23 | + ~noisy_resource() { std::print("destroy noisy\n"); } |
25 | 24 | }; |
26 | 25 |
|
27 | | -int main() |
28 | | -{ |
| 26 | +int main() { |
29 | 27 |
|
30 | | - bool exit_ran, success_ran, fail_ran = false; |
31 | | - { |
32 | | - std::print( "--> scope start\n" ); |
33 | | - beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); |
34 | | - beman::scope::scope_success _([&success_ran]{ success_ran = true;}); |
35 | | - beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); |
36 | | - auto resource_ptr = beman::scope::unique_resource |
37 | | - ( |
38 | | - new noisy_resource(), |
39 | | - // Cleanup function |
40 | | - [](noisy_resource* ptr) { delete ptr; } |
41 | | - ); |
42 | | - std::print( "--> scope end\n"); |
43 | | - } // Normal scope exit |
| 28 | + bool exit_ran, success_ran, fail_ran = false; |
| 29 | + { |
| 30 | + std::print("--> scope start\n"); |
| 31 | + beman::scope::scope_exit _([&exit_ran] { exit_ran = true; }); |
| 32 | + beman::scope::scope_success _([&success_ran] { success_ran = true; }); |
| 33 | + beman::scope::scope_fail _([&fail_ran] { fail_ran = true; }); |
| 34 | + auto resource_ptr = beman::scope::unique_resource(new noisy_resource(), |
| 35 | + // Cleanup function |
| 36 | + [](noisy_resource* ptr) { delete ptr; }); |
| 37 | + std::print("--> scope end\n"); |
| 38 | + } // Normal scope exit |
44 | 39 |
|
45 | | - std::print("scope exit: {} success: {} fail: {} \n", |
46 | | - exit_ran, success_ran, fail_ran); |
| 40 | + std::print("scope exit: {} success: {} fail: {} \n", exit_ran, success_ran, fail_ran); |
47 | 41 | } |
0 commit comments