17 #ifndef COM_BORA_SOFTWARE__BALAU_TYPE__MOVEABLE_ON_SCOPE_EXIT 18 #define COM_BORA_SOFTWARE__BALAU_TYPE__MOVEABLE_ON_SCOPE_EXIT 42 : exiter(new ContainerImpl<FunctionT>(function)) {}
48 : exiter(std::move(rhs.exiter)) {}
69 private:
struct ContainerBase {
70 virtual ~ContainerBase() =
default;
71 public:
virtual void clear() = 0;
72 public:
virtual void reset(std::function<
void ()> function_) = 0;
76 private:
template <
typename FunctionT>
struct ContainerImpl :
public ContainerBase {
77 explicit ContainerImpl(FunctionT function_) :
function(function_) {}
79 ~ContainerImpl()
override {
83 ContainerImpl(
const ContainerImpl &) =
delete;
84 ContainerImpl & operator =(
const ContainerImpl &) =
delete;
86 public:
void clear()
override {
96 private: FunctionT
function;
99 private: std::unique_ptr<ContainerBase> exiter;
104 #endif // COM_BORA_SOFTWARE__BALAU_TYPE__MOVEABLE_ON_SCOPE_EXIT Run a function on scope exit (movable version).
Definition: MovableOnScopeExit.hpp:37
void executeNow()
Execute the function now and then clear it.
Definition: MovableOnScopeExit.hpp:60
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
MovableOnScopeExit(MovableOnScopeExit &&rhs) noexcept
Move the scope exit running to a different instance.
Definition: MovableOnScopeExit.hpp:47
void clear()
Set to the function to NOP (cancels scheduled execution).
Definition: MovableOnScopeExit.hpp:53
MovableOnScopeExit(FunctionT function)
Run the function on scope exit.
Definition: MovableOnScopeExit.hpp:41