summaryrefslogtreecommitdiff
path: root/src/common/scope_exit.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/scope_exit.h23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h
index 08f09a8c8..73b2a262e 100644
--- a/src/common/scope_exit.h
+++ b/src/common/scope_exit.h
@@ -4,20 +4,25 @@
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 }
15 ~ScopeExitHelper() {
16 func();
17 }
15 18
16 Func func; 19 Func func;
17 }; 20};
18 21
19 template <typename Func> 22template <typename Func>
20 ScopeExitHelper<Func> ScopeExit(Func&& func) { return ScopeExitHelper<Func>(std::move(func)); } 23ScopeExitHelper<Func> ScopeExit(Func&& func) {
24 return ScopeExitHelper<Func>(std::move(func));
25}
21} 26}
22 27
23/** 28/**