Nui
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
scope_exit.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <functional>
6#include <type_traits>
7#include <utility>
8
9namespace Nui
10{
12 {
13 public:
14 template <typename FunctionT>
15 requires std::is_nothrow_invocable_v<FunctionT>
16 explicit ScopeExit(FunctionT&& func)
17 : onExit_(std::forward<FunctionT>(func))
18 {}
20 {
21 if (onExit_)
22 onExit_();
23 }
24 ScopeExit(ScopeExit&& other) = delete;
25 ScopeExit& operator=(ScopeExit&& other) = delete;
26 ScopeExit(const ScopeExit&) = delete;
27 ScopeExit& operator=(const ScopeExit&) = delete;
28 void disarm()
29 {
30 onExit_ = {};
31 }
32
33 private:
34 std::function<void()> onExit_;
35 };
36
37 namespace Detail
38 {
39 struct MakeScopeExitImpl
40 {
41 template <typename FunctionT>
42 auto operator->*(FunctionT&& fn) const
43 {
44 return ScopeExit{std::forward<FunctionT>(fn)};
45 }
46 };
47 }
48
49#define NUI_ON_SCOPE_EXIT auto NUI_UNIQUE_IDENTIFIER = ::Nui::Detail::MakeScopeExitImpl{}->*[&]() noexcept
50}
Definition scope_exit.hpp:12
ScopeExit(ScopeExit &&other)=delete
ScopeExit(FunctionT &&func)
Definition scope_exit.hpp:16
~ScopeExit()
Definition scope_exit.hpp:19
ScopeExit(const ScopeExit &)=delete
ScopeExit & operator=(const ScopeExit &)=delete
void disarm()
Definition scope_exit.hpp:28
ScopeExit & operator=(ScopeExit &&other)=delete
static constexpr auto extractJsonMember(nlohmann::json const &json) -> decltype(auto)
Definition rpc_hub.hpp:29
Definition file_dialog.hpp:6