FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
scoped_guard.hpp
1
21#pragma once
22
23#include <functional>
24
26{
27 public:
28 template <class Callable> explicit ScopeGuard(Callable&& cleanupFunction)
29 try : f(std::forward<Callable>(cleanupFunction))
30 {
31 }
32 catch (...)
33 {
34 cleanupFunction();
35 throw;
36 }
37
39 {
40 if (f)
41 f();
42 }
43
44 void dismiss() noexcept
45 {
46 f = nullptr;
47 }
48
49 ScopeGuard(const ScopeGuard&) = delete;
50 ScopeGuard(ScopeGuard&& other) noexcept = delete;
51 ScopeGuard& operator=(const ScopeGuard&) = delete;
52 ScopeGuard& operator=(const ScopeGuard&&) = delete;
53
54 private:
55 std::function<void()> f;
56};