1 //===-- CleanUp.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_CleanUp_h_
11 #define liblldb_CleanUp_h_
13 #include "lldb/lldb-public.h"
16 namespace lldb_private {
18 /// Run a cleanup function on scope exit unless it's explicitly disabled.
20 std::function<void()> Clean;
23 /// Register a cleanup function which applies \p Func to a list of arguments.
24 /// Use caution with arguments which are references: they will be copied.
25 template <typename F, typename... Args>
26 CleanUp(F &&Func, Args &&... args)
27 : Clean(std::bind(std::forward<F>(Func), std::forward<Args>(args)...)) {}
34 /// Disable the cleanup.
35 void disable() { Clean = nullptr; }
37 // Prevent cleanups from being run more than once.
38 DISALLOW_COPY_AND_ASSIGN(CleanUp);
41 } // namespace lldb_private
43 #endif // #ifndef liblldb_CleanUp_h_