Caffe2 - C++ API
A deep learning, cross platform ML framework
resource_guard.h
1 #pragma once
2 #include <functional>
3 
4 namespace torch {
5 namespace jit {
6 
7 class ResourceGuard {
8  std::function<void()> _destructor;
9  bool _released;
10 
11  public:
12  ResourceGuard(std::function<void()> destructor)
13  : _destructor(std::move(destructor)), _released(false) {}
14 
15  ~ResourceGuard() {
16  if (!_released)
17  _destructor();
18  }
19 
20  void release() {
21  _released = true;
22  }
23 };
24 
25 } // namespace jit
26 } // namespace torch
Definition: jit_type.h:17