You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+72-1Lines changed: 72 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,12 @@
6
6
7
7
## Overview
8
8
9
-
This project provides a set of scope guard utilities for managing exit actions in C++. These utilities ensure that specified actions are executed when a scope is exited, regardless of how the exit occurs. The scope guards include:
9
+
This project provides a set of utilities for managing exit actions and resource handling in C++. These utilities ensure that specified actions are executed when a scope is exited, regardless of (or depending on) how the exit occurs. The scope guards include:
10
10
11
11
-`exit_action`: Executes an action when the scope is exited.
12
12
-`fail_action`: Executes an action when the scope is exited due to an exception.
13
13
-`success_action`: Executes an action when the scope is exited normally.
14
+
-`unique_resource`: Manages a resource through a handle and disposes of that resource upon destruction (scope exit).
14
15
15
16
These utilities are useful for ensuring that resources are properly released or actions are taken when a scope is exited.
16
17
@@ -19,11 +20,14 @@ These utilities are useful for ensuring that resources are properly released or
19
20
-**exit_action**: Calls its exit function on destruction, when a scope is exited.
20
21
-**fail_action**: Calls its exit function when a scope is exited via an exception.
21
22
-**success_action**: Calls its exit function when a scope is exited normally.
23
+
-**unique_resource**: Manages a resource with a custom deleter, ensuring the resource is released when the scope is exited.
22
24
23
25
## Usage
24
26
25
27
### Example Usage
26
28
29
+
#### Scope Guards
30
+
27
31
```cpp
28
32
#include<iostream>
29
33
#include<scope_action.h>
@@ -77,6 +81,29 @@ int main()
77
81
}
78
82
```
79
83
84
+
#### `unique_resource`
85
+
86
+
```cpp
87
+
#include <cstdio>
88
+
#include <unique_resource.h>
89
+
90
+
int main()
91
+
{
92
+
auto file = wwa::utils::make_unique_resource_checked(
The documentation is available at [https://sjinks.github.io/scope-action-cpp/](https://sjinks.github.io/scope-action-cpp/).
@@ -144,6 +171,50 @@ public:
144
171
};
145
172
```
146
173
174
+
### `unique_resource`
175
+
176
+
A universal RAII resource handle wrapper for resource handles that owns and manages a resource through a handle and disposes of that resource upon destruction.
0 commit comments