mirror of
https://github.com/microsoft/GSL.git
synced 2025-04-01 08:56:29 -04:00
Merge 9f1f78d68098aedbe5fc5d2bc6d0161b6f6ad4e3 into 355982daf6c54ccb11bef8a1c511be2622dec402
This commit is contained in:
commit
21f9620836
@ -50,7 +50,7 @@ dyn_array | &
|
||||
[**4. Utilities**][cg-utilities] | |
|
||||
move_owner | ☐ | A helper function that moves one `owner` to the other
|
||||
[byte](docs/headers.md#user-content-H-byte-byte) | ☑ | Either an alias to `std::byte` or a byte type
|
||||
[final_action](docs/headers.md#user-content-H-util-final_action) | ☑ | A RAII style class that invokes a functor on its destruction
|
||||
[final_action](docs/headers.md#user-content-H-util-final_action) | ☑ | A RAII style class that invokes a non-throwing functor on its destruction
|
||||
[finally](docs/headers.md#user-content-H-util-finally) | ☑ | A helper function instantiating [final_action](docs/headers.md#user-content-H-util-final_action)
|
||||
[GSL_SUPPRESS](docs/headers.md#user-content-H-assert-gsl_suppress) | ☑ | A macro that takes an argument and turns it into `[[gsl::suppress(x)]]` or `[[gsl::suppress("x")]]`
|
||||
[[implicit]] | ☐ | A "marker" to put on single-argument constructors to explicitly make them non-explicit
|
||||
|
@ -794,7 +794,7 @@ template <class F>
|
||||
class final_action { ... };
|
||||
```
|
||||
|
||||
`final_action` allows you to ensure something gets run at the end of a scope.
|
||||
`final_action` allows you to ensure non-throwing code is executed at the end of a scope.
|
||||
|
||||
See [E.19: Use a final_action object to express cleanup if no suitable resource handle is available](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Re-finally)
|
||||
|
||||
@ -805,13 +805,13 @@ explicit final_action(const F& ff) noexcept;
|
||||
explicit final_action(F&& ff) noexcept;
|
||||
```
|
||||
|
||||
Construct an object with the action to invoke in the destructor.
|
||||
Construct an object with the non-throwing action to invoke in the destructor.
|
||||
|
||||
```cpp
|
||||
~final_action() noexcept;
|
||||
```
|
||||
|
||||
The destructor will call the action that was passed in the constructor.
|
||||
The destructor will invoke the action that was passed in the constructor; if the action throws an exception the program will terminate.
|
||||
|
||||
```cpp
|
||||
final_action(final_action&& other) noexcept;
|
||||
|
@ -69,10 +69,12 @@ namespace gsl
|
||||
// index type for all container indexes/subscripts/sizes
|
||||
using index = std::ptrdiff_t;
|
||||
|
||||
// final_action allows you to ensure something gets run at the end of a scope
|
||||
// final_action allows you to ensure non-throwing code is executed at the end of a scope.
|
||||
template <class F>
|
||||
class final_action
|
||||
{
|
||||
static_assert(std::is_nothrow_invocable_v<F>, "the provided action must be non-throwing");
|
||||
|
||||
public:
|
||||
explicit final_action(const F& ff) noexcept : f{ff} { }
|
||||
explicit final_action(F&& ff) noexcept : f{std::move(ff)} { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user