Enigma  3.2.0
A Simple, Reliable and Efficient Encryption Tool
FinalAction.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <Core/Core.hpp>
3 #include <utility>
4 
8 template<class F>
9 class FinalAction {
10  public:
11  explicit FinalAction(const F& ff) noexcept : f{ff} {}
12  explicit FinalAction(F&& ff) noexcept : f{std::move(ff)} {}
13 
14  ~FinalAction() noexcept {
15  if (invoke) f();
16  }
17 
18  FinalAction(FinalAction&& other) noexcept
19  : f(std::move(other.f)), invoke(std::exchange(other.invoke, false)) {}
20 
21  FinalAction(const FinalAction&) = delete;
22  void operator=(const FinalAction&) = delete;
23  void operator=(FinalAction&&) = delete;
24 
25  private:
26  F f;
27  bool invoke = true;
28 };
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition: Macros.hpp:13
#define NS_ENIGMA_END
Definition: Macros.hpp:14
Executes a function at the end of the scope (deferred) using RAII gsl libs.
Definition: FinalAction.hpp:9
void operator=(const FinalAction &)=delete
FinalAction(const F &ff) noexcept
Definition: FinalAction.hpp:11
FinalAction(F &&ff) noexcept
Definition: FinalAction.hpp:12
FinalAction(const FinalAction &)=delete
~FinalAction() noexcept
Definition: FinalAction.hpp:14
void operator=(FinalAction &&)=delete
FinalAction(FinalAction &&other) noexcept
Definition: FinalAction.hpp:18