# stdex: include/stdex/scoped_executor.hpp Source File

Loading...
Searching...
No Matches
scoped_executor.hpp
/*
SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis
*/
#pragma once
#include "compat.hpp"
namespace stdex
{
template <typename F_init, typename F_done>
class scoped_executor
{
F_done&& m_done;
public:
scoped_executor(_In_ F_init&& init, _In_ F_done&& done) : m_done(std::forward<F_done&&>(done))
{
std::forward<F_init&&>(init)();
}
~scoped_executor()
{
std::forward<F_done&&>(m_done)();
}
};
}
stdex::scoped_executor
Executes one lambda immediately, and another when exiting the scope.
Definition scoped_executor.hpp:20
stdex::scoped_executor::scoped_executor
scoped_executor(F_init &&init, F_done &&done)
Executes init immediately and saves done for destructor.
Definition scoped_executor.hpp:30
stdex::scoped_executor::~scoped_executor
~scoped_executor()
Executes done lambda.
Definition scoped_executor.hpp:38