mirror of
https://github.com/microsoft/GSL.git
synced 2025-04-02 09:18:33 -04:00
enforcement for no-throw finally actions
a throwing finally action will be accepted by the compiler but result in surprise termination at runtime; enforce that actions provided to finally must be non-throwing at compile time.
This commit is contained in:
parent
5a66c65d09
commit
8c165a4199
@ -73,6 +73,8 @@ using index = std::ptrdiff_t;
|
|||||||
template <class F>
|
template <class F>
|
||||||
class final_action
|
class final_action
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_nothrow_invocable_v<F>, "the provided action must be non-throwing");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit final_action(const F& ff) noexcept : f{ff} { }
|
explicit final_action(const F& ff) noexcept : f{ff} { }
|
||||||
explicit final_action(F&& ff) noexcept : f{std::move(ff)} { }
|
explicit final_action(F&& ff) noexcept : f{std::move(ff)} { }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user