25template <
typename Callback>
26class FastScopeGuard final {
28 static_assert(std::is_nothrow_move_constructible_v<Callback>);
31 std::is_nothrow_invocable_r_v<
void, Callback&&>,
32 "If the functions called in the body of the lambda are all 'noexcept', "
33 "please mark the lambda itself as 'noexcept'. If however, the contents "
34 "are not 'noexcept', use 'ScopeGuard' instead of 'FastScopeGuard'.");
36 constexpr explicit FastScopeGuard(Callback callback)
noexcept
37 : callback_(std::move(callback)) {}
39 constexpr FastScopeGuard(FastScopeGuard&& other)
noexcept
40 : callback_(std::move(other.callback_)),
41 is_active_(std::exchange(other.is_active_,
false)) {}
43 constexpr FastScopeGuard& operator=(FastScopeGuard&& other)
noexcept {
45 callback_ = std::move(other.callback_);
46 is_active_ = std::exchange(other.is_active_,
false);
52 if (is_active_) std::move(callback_)();
55 constexpr void Release()
noexcept { is_active_ =
false; }
61 bool is_active_{
true};