Nui
scope_exit.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <functional>
6 #include <utility>
7 
8 namespace Nui
9 {
10  template <typename EF>
11  class ScopeExit
12  {
13  public:
14  ScopeExit(EF&& func)
15  : onExit_(std::forward<EF>(func))
16  {}
18  {
19  onExit_();
20  }
21  void disarm()
22  {
23  onExit_ = [] {};
24  }
25 
26  private:
27  std::function<void()> onExit_;
28  };
29  template <typename T>
31 
32  namespace Detail
33  {
35  {
36  template <typename FunctionT>
37  auto operator->*(FunctionT&& fn) const
38  {
39  return ScopeExit<FunctionT>(std::forward<FunctionT>(fn));
40  }
41  };
42  }
43 
44 #define NUI_ON_SCOPE_EXIT auto NUI_UNIQUE_IDENTIFIER = ::Nui::Detail::MakeScopeExitImpl{}->*[&]
45 }
Definition: scope_exit.hpp:12
void disarm()
Definition: scope_exit.hpp:21
~ScopeExit()
Definition: scope_exit.hpp:17
ScopeExit(EF &&func)
Definition: scope_exit.hpp:14
Definition: file_dialog.hpp:6
ScopeExit(T) -> ScopeExit< T >
Definition: scope_exit.hpp:35
auto operator->*(FunctionT &&fn) const
Definition: scope_exit.hpp:37