RESTinio
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 
21 namespace restinio {
22 
23 namespace utils {
24 
25 namespace scope_exit_details {
26 
27 /*!
28  * \brief Helper class for scope exit implementation.
29  */
30 template< typename L >
31 class at_exit_t
32  {
34  public :
35  at_exit_t( L && l ) : m_lambda{ std::forward<L>(l) } {}
37  ~at_exit_t() { 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  */
58 template< typename L >
60 at_scope_exit( L && l )
61  {
62  return scope_exit_details::at_exit_t<L>{ std::forward<L>(l) };
63  }
64 
65 } /* namespace utils */
66 
67 } /* namespace restinio */
void normalize_to(string_view_t what, char *dest)
Perform normalization of URI value.
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.
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
Definition: value_or.hpp:64