Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
ScopeGuard.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-present, Facebook, Inc.
3 * All rights reserved.
4 *
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).
8 */
9#pragma once
10
11#include <utility>
12
13namespace pzstd {
14
25template <typename Function>
26class ScopeGuard {
27 Function function;
28 bool dismissed;
29
30 public:
31 explicit ScopeGuard(Function&& function)
32 : function(std::move(function)), dismissed(false) {}
33
34 void dismiss() {
35 dismissed = true;
36 }
37
38 ~ScopeGuard() noexcept {
39 if (!dismissed) {
40 function();
41 }
42 }
43};
44
46template <typename Function>
48 return ScopeGuard<Function>(std::forward<Function>(function));
49}
50}
Definition ScopeGuard.h:26
void dismiss()
Definition ScopeGuard.h:34
~ScopeGuard() noexcept
Definition ScopeGuard.h:38
ScopeGuard(Function &&function)
Definition ScopeGuard.h:31
Definition ErrorHolder.h:16
ScopeGuard< Function > makeScopeGuard(Function &&function)
Creates a scope guard from function.
Definition ScopeGuard.h:47
#define false
Definition longfile.c:42