Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scope_guard.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <functional>
19 
20 namespace tc {
21 
22 //
23 // Poor man's ScopeGuard
24 //
25 class ScopeGuard {
26  std::function<void()> onExit;
27  ScopeGuard() = delete;
28  ScopeGuard(ScopeGuard&) = delete;
29  ScopeGuard(ScopeGuard&&) = delete;
30  ScopeGuard operator=(ScopeGuard&) = delete;
31  ScopeGuard operator=(ScopeGuard&&) = delete;
32 
33  public:
34  template <class F>
35  ScopeGuard(const F& f) : onExit(f) {}
36  ~ScopeGuard() noexcept(false) {
37  onExit();
38  }
39 };
40 
41 } // namespace tc
~ScopeGuard() noexcept(false)
Definition: scope_guard.h:36
Definition: scope_guard.h:25
ScopeGuard()=delete
std::function< void()> onExit
Definition: scope_guard.h:26
ScopeGuard operator=(ScopeGuard &)=delete
ScopeGuard(const F &f)
Definition: scope_guard.h:35