stdex Additional custom or not Standard C++ covered algorithms

Loading...
Searching...
No Matches
scoped_executor.hpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023-2024 Amebis
4*/
5
6#pragma once
7
8#include "compat.hpp"
9
10 namespace stdex
11{
18 template <typename F_init, typename F_done>
19 class scoped_executor
20 {
21 F_done&& m_done;
22
23 public:
30 scoped_executor(_In_ F_init&& init, _In_ F_done&& done) : m_done(std::forward<F_done&&>(done))
31 {
32 std::forward<F_init&&>(init)();
33 }
34
38 ~scoped_executor()
39 {
40 std::forward<F_done&&>(m_done)();
41 }
42 };
43}
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