RESTinio
Loading...
Searching...
No Matches
at_scope_exit.hpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5, RESTinio
3 */
4
5/*!
6 * @file
7 * @brief A simple implementation of %at_scope_exit concept.
8 *
9 * @note
10 * This code is borrowed from SObjectizer project:
11 * https://github.com/stiffstream/sobjectizer
12 *
13 * @since
14 * v.0.6.4
15 */
16
17#pragma once
18
19#include <utility>
20
21namespace restinio {
22
23namespace utils {
24
26
27/*!
28 * \brief Helper class for scope exit implementation.
29 */
30template< typename L >
32 {
34 public :
35 at_exit_t( L && l ) : m_lambda{ std::forward<L>(l) } {}
36 at_exit_t( at_exit_t && o ) : m_lambda{ std::move(o.m_lambda) } {}
38 };
39
40} /* namespace scope_exit_details */
41
42/*!
43 * \brief Helper function for creation action to be performed at scope exit.
44 *
45 * Usage example:
46 * \code
47 if( needs_wait )
48 {
49 m_threads_to_wakeup += 1;
50 auto decrement_threads = at_scope_exit( [&m_threads_to_wakeup] {
51 --m_threads_to_wakeup;
52 } );
53 m_sleep_cond.wait_for( some_time, some_predicate );
54 }
55 * \endcode
56 *
57 */
58template< typename L >
61 {
62 return scope_exit_details::at_exit_t<L>{ std::forward<L>(l) };
63 }
64
65} /* namespace utils */
66
67} /* namespace restinio */
Helper class for scope exit implementation.
scope_exit_details::at_exit_t< L > at_scope_exit(L &&l)
Helper function for creation action to be performed at scope exit.