Skip to content

Commit

Permalink
E.19: clarify that finally is from the GSL (isocpp#1936)
Browse files Browse the repository at this point in the history
When I stumbled upon E.19 "Use a `final_action` object to express
cleanup if no suitable resource handle is available" I was hopeful
that this `final_action`/`finally()` thing is from the STL, but, alas,
it isn't.

Make it clear that `finally` is a GSL construct.
  • Loading branch information
szeder authored Jul 13, 2022
1 parent fde9ee5 commit 42c4cc6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -16216,14 +16216,14 @@ Better:

##### Reason

`finally` is less verbose and harder to get wrong than `try`/`catch`.
`finally` from the [GSL](#S-gsl) is less verbose and harder to get wrong than `try`/`catch`.

##### Example

void f(int n)
{
void* p = malloc(n);
auto _ = finally([p] { free(p); });
auto _ = gsl::finally([p] { free(p); });
// ...
}

Expand Down

0 comments on commit 42c4cc6

Please sign in to comment.