summaryrefslogtreecommitdiff
path: root/src/common/scope_exit.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/scope_exit.h')
-rw-r--r--src/common/scope_exit.h22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h
index 08f09a8c8..072ab285d 100644
--- a/src/common/scope_exit.h
+++ b/src/common/scope_exit.h
@@ -4,20 +4,24 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "common/common_funcs.h"
8#include <utility> 7#include <utility>
8#include "common/common_funcs.h"
9 9
10namespace detail { 10namespace detail {
11 template <typename Func> 11template <typename Func>
12 struct ScopeExitHelper { 12struct ScopeExitHelper {
13 explicit ScopeExitHelper(Func&& func) : func(std::move(func)) {} 13 explicit ScopeExitHelper(Func&& func) : func(std::move(func)) {}
14 ~ScopeExitHelper() { func(); } 14 ~ScopeExitHelper() {
15 func();
16 }
15 17
16 Func func; 18 Func func;
17 }; 19};
18 20
19 template <typename Func> 21template <typename Func>
20 ScopeExitHelper<Func> ScopeExit(Func&& func) { return ScopeExitHelper<Func>(std::move(func)); } 22ScopeExitHelper<Func> ScopeExit(Func&& func) {
23 return ScopeExitHelper<Func>(std::move(func));
24}
21} 25}
22 26
23/** 27/**