tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
scope_exit.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3#ifndef TETL_SCOPE_SCOPE_EXIT_HPP
4#define TETL_SCOPE_SCOPE_EXIT_HPP
5
6#include <etl/_scope/scope_guard.hpp>
7
8namespace etl {
9
10/// \brief The class template `scope_exit` is a general-purpose scope guard
11/// intended to call its exit function when a scope is exited. \details A
12/// `scope_exit` may be either active, i.e. calls its exit function on
13/// destruction, or inactive, i.e. does nothing on destruction. A `scope_exit`
14/// is active after constructed from an exit function. A `scope_exit` can become
15/// inactive by calling `release()` on it either manually or automatically (by
16/// the move constructor). An inactive `scope_exit` may also be obtained by
17/// initializing with another inactive `scope_exit`. Once a `scope_exit` is
18/// inactive, it cannot become active again.
19template <typename FuncT>
20struct scope_exit : detail::scope_guard<FuncT, detail::scope_exit_impl> {
21 /// Creates a scope_exit from a function, a function object or another
22 /// scope_exit.
23 using detail::scope_guard<FuncT, detail::scope_exit_impl>::scope_guard;
24};
25
26// Deduction guide
27template <typename FuncT>
28scope_exit(FuncT) -> scope_exit<decay_t<FuncT>>;
29
30} // namespace etl
31
32#endif // TETL_SCOPE_SCOPE_EXIT_HPP
Definition adjacent_find.hpp:9
scope_exit(FuncT) -> scope_exit< decay_t< FuncT > >
The class template scope_exit is a general-purpose scope guard intended to call its exit function whe...
Definition scope_exit.hpp:20