]>
git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/contrib/pzstd/utils/ScopeGuard.h
2 * Copyright (c) 2016-present, Facebook, Inc.
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
16 * Dismissable scope guard.
17 * `Function` must be callable and take no parameters.
18 * Unless `dissmiss()` is called, the callable is executed upon destruction of
23 * auto guard = makeScopeGuard([&] { cleanup(); });
25 template <typename Function
>
31 explicit ScopeGuard(Function
&& function
)
32 : function(std::move(function
)), dismissed(false) {}
38 ~ScopeGuard() noexcept
{
45 /// Creates a scope guard from `function`.
46 template <typename Function
>
47 ScopeGuard
<Function
> makeScopeGuard(Function
&& function
) {
48 return ScopeGuard
<Function
>(std::forward
<Function
>(function
));