]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/bind_handler.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / core / bind_handler.hpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_BIND_HANDLER_HPP
11 #define BOOST_BEAST_BIND_HANDLER_HPP
12
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/type_traits.hpp>
15 #include <boost/beast/core/detail/bind_handler.hpp>
16 #include <type_traits>
17 #include <utility>
18
19 namespace boost {
20 namespace beast {
21
22 /** Bind parameters to a completion handler, creating a new handler.
23
24 This function creates a new handler which, when invoked, calls
25 the original handler with the list of bound arguments. Any
26 parameters passed in the invocation will be subtituted for
27 placeholders present in the list of bound arguments. Parameters
28 which are not matched to placeholders are silently discarded.
29 The passed handler and arguments are forwarded into the returned
30 handler, which provides the same `io_context` execution guarantees
31 as the original handler.
32
33 Unlike `boost::asio::io_context::wrap`, the returned handler can
34 be used in a subsequent call to `boost::asio::io_context::post`
35 instead of `boost::asio::io_context::dispatch`, to ensure that
36 the handler will not be invoked immediately by the calling
37 function.
38
39 Example:
40
41 @code
42 template<class AsyncReadStream, class ReadHandler>
43 void
44 signal_aborted(AsyncReadStream& stream, ReadHandler&& handler)
45 {
46 boost::asio::post(
47 stream.get_executor(),
48 bind_handler(std::forward<ReadHandler>(handler),
49 boost::asio::error::operation_aborted, 0));
50 }
51 @endcode
52
53 @param handler The handler to wrap.
54
55 @param args A list of arguments to bind to the handler. The
56 arguments are forwarded into the returned object.
57 */
58 template<class Handler, class... Args>
59 #if BOOST_BEAST_DOXYGEN
60 implementation_defined
61 #else
62 detail::bound_handler<
63 typename std::decay<Handler>::type, Args...>
64 #endif
65 bind_handler(Handler&& handler, Args&&... args)
66 {
67 #if 0
68 static_assert(is_completion_handler<
69 Handler, void(Args...)>::value,
70 "Handler requirements not met");
71 #endif
72 return detail::bound_handler<typename std::decay<
73 Handler>::type, Args...>(std::forward<
74 Handler>(handler), std::forward<Args>(args)...);
75 }
76
77 } // beast
78 } // boost
79
80 #endif