Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / asio / post.hpp
1 //
2 // post.hpp
3 // ~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #ifndef BOOST_ASIO_POST_HPP
12 #define BOOST_ASIO_POST_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/async_result.hpp>
20 #include <boost/asio/detail/type_traits.hpp>
21 #include <boost/asio/execution_context.hpp>
22 #include <boost/asio/is_executor.hpp>
23
24 #include <boost/asio/detail/push_options.hpp>
25
26 namespace boost {
27 namespace asio {
28
29 /// Submits a completion token or function object for execution.
30 /**
31  * This function submits an object for execution using the object's associated
32  * executor. The function object is queued for execution, and is never called
33  * from the current thread prior to returning from <tt>post()</tt>.
34  *
35  * The use of @c post(), rather than @ref defer(), indicates the caller's
36  * preference that the function object be eagerly queued for execution.
37  *
38  * This function has the following effects:
39  *
40  * @li Constructs a function object handler of type @c Handler, initialized
41  * with <tt>handler(forward<CompletionToken>(token))</tt>.
42  *
43  * @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
44  * initializing the object as <tt>result(handler)</tt>.
45  *
46  * @li Obtains the handler's associated executor object @c ex by performing
47  * <tt>get_associated_executor(handler)</tt>.
48  *
49  * @li Obtains the handler's associated allocator object @c alloc by performing
50  * <tt>get_associated_allocator(handler)</tt>.
51  *
52  * @li Performs <tt>ex.post(std::move(handler), alloc)</tt>.
53  *
54  * @li Returns <tt>result.get()</tt>.
55  */
56 template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
57 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post(
58     BOOST_ASIO_MOVE_ARG(CompletionToken) token);
59
60 /// Submits a completion token or function object for execution.
61 /**
62  * This function submits an object for execution using the specified executor.
63  * The function object is queued for execution, and is never called from the
64  * current thread prior to returning from <tt>post()</tt>.
65  *
66  * The use of @c post(), rather than @ref defer(), indicates the caller's
67  * preference that the function object be eagerly queued for execution.
68  *
69  * This function has the following effects:
70  *
71  * @li Constructs a function object handler of type @c Handler, initialized
72  * with <tt>handler(forward<CompletionToken>(token))</tt>.
73  *
74  * @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
75  * initializing the object as <tt>result(handler)</tt>.
76  *
77  * @li Obtains the handler's associated executor object @c ex1 by performing
78  * <tt>get_associated_executor(handler)</tt>.
79  *
80  * @li Creates a work object @c w by performing <tt>make_work(ex1)</tt>.
81  *
82  * @li Obtains the handler's associated allocator object @c alloc by performing
83  * <tt>get_associated_allocator(handler)</tt>.
84  *
85  * @li Constructs a function object @c f with a function call operator that
86  * performs <tt>ex1.dispatch(std::move(handler), alloc)</tt> followed by
87  * <tt>w.reset()</tt>.
88  *
89  * @li Performs <tt>Executor(ex).post(std::move(f), alloc)</tt>.
90  *
91  * @li Returns <tt>result.get()</tt>.
92  */
93 template <typename Executor,
94     BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken
95       BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(Executor)>
96 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post(
97     const Executor& ex,
98     BOOST_ASIO_MOVE_ARG(CompletionToken) token
99       BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(Executor),
100     typename enable_if<is_executor<Executor>::value>::type* = 0);
101
102 /// Submits a completion token or function object for execution.
103 /**
104  * @returns <tt>post(ctx.get_executor(), forward<CompletionToken>(token))</tt>.
105  */
106 template <typename ExecutionContext,
107     BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken
108       BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(
109         typename ExecutionContext::executor_type)>
110 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) post(
111     ExecutionContext& ctx,
112     BOOST_ASIO_MOVE_ARG(CompletionToken) token
113       BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(
114         typename ExecutionContext::executor_type),
115     typename enable_if<is_convertible<
116       ExecutionContext&, execution_context&>::value>::type* = 0);
117
118 } // namespace asio
119 } // namespace boost
120
121 #include <boost/asio/detail/pop_options.hpp>
122
123 #include <boost/asio/impl/post.hpp>
124
125 #endif // BOOST_ASIO_POST_HPP