File indexing completed on 2026-05-10 08:43:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_ADT_SCOPEEXIT_H
0016 #define LLVM_ADT_SCOPEEXIT_H
0017
0018 #include "llvm/Support/Compiler.h"
0019
0020 #include <type_traits>
0021 #include <utility>
0022
0023 namespace llvm {
0024 namespace detail {
0025
0026 template <typename Callable> class scope_exit {
0027 Callable ExitFunction;
0028 bool Engaged = true;
0029
0030 public:
0031 template <typename Fp>
0032 explicit scope_exit(Fp &&F) : ExitFunction(std::forward<Fp>(F)) {}
0033
0034 scope_exit(scope_exit &&Rhs)
0035 : ExitFunction(std::move(Rhs.ExitFunction)), Engaged(Rhs.Engaged) {
0036 Rhs.release();
0037 }
0038 scope_exit(const scope_exit &) = delete;
0039 scope_exit &operator=(scope_exit &&) = delete;
0040 scope_exit &operator=(const scope_exit &) = delete;
0041
0042 void release() { Engaged = false; }
0043
0044 ~scope_exit() {
0045 if (Engaged)
0046 ExitFunction();
0047 }
0048 };
0049
0050 }
0051
0052
0053
0054
0055
0056
0057 template <typename Callable>
0058 [[nodiscard]] detail::scope_exit<std::decay_t<Callable>>
0059 make_scope_exit(Callable &&F) {
0060 return detail::scope_exit<std::decay_t<Callable>>(std::forward<Callable>(F));
0061 }
0062
0063 }
0064
0065 #endif