]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/impl/defer.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / impl / defer.hpp
1 //
2 // impl/defer.hpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 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_IMPL_DEFER_HPP
12 #define BOOST_ASIO_IMPL_DEFER_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/associated_allocator.hpp>
20 #include <boost/asio/associated_executor.hpp>
21 #include <boost/asio/detail/work_dispatcher.hpp>
22
23 #include <boost/asio/detail/push_options.hpp>
24
25 namespace boost {
26 namespace asio {
27
28 template <typename CompletionToken>
29 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer(
30 BOOST_ASIO_MOVE_ARG(CompletionToken) token)
31 {
32 typedef BOOST_ASIO_HANDLER_TYPE(CompletionToken, void()) handler;
33
34 async_completion<CompletionToken, void()> init(token);
35
36 typename associated_executor<handler>::type ex(
37 (get_associated_executor)(init.completion_handler));
38
39 typename associated_allocator<handler>::type alloc(
40 (get_associated_allocator)(init.completion_handler));
41
42 ex.defer(BOOST_ASIO_MOVE_CAST(handler)(init.completion_handler), alloc);
43
44 return init.result.get();
45 }
46
47 template <typename Executor, typename CompletionToken>
48 BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer(
49 const Executor& ex, BOOST_ASIO_MOVE_ARG(CompletionToken) token,
50 typename enable_if<is_executor<Executor>::value>::type*)
51 {
52 typedef BOOST_ASIO_HANDLER_TYPE(CompletionToken, void()) handler;
53
54 async_completion<CompletionToken, void()> init(token);
55
56 typename associated_allocator<handler>::type alloc(
57 (get_associated_allocator)(init.completion_handler));
58
59 ex.defer(detail::work_dispatcher<handler>(init.completion_handler), alloc);
60
61 return init.result.get();
62 }
63
64 template <typename ExecutionContext, typename CompletionToken>
65 inline BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer(
66 ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(CompletionToken) token,
67 typename enable_if<is_convertible<
68 ExecutionContext&, execution_context&>::value>::type*)
69 {
70 return (defer)(ctx.get_executor(),
71 BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
72 }
73
74 } // namespace asio
75 } // namespace boost
76
77 #include <boost/asio/detail/pop_options.hpp>
78
79 #endif // BOOST_ASIO_IMPL_DEFER_HPP