]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/bind_handler.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / beast / core / bind_handler.hpp
1 //
2 // Copyright (c) 2016-2019 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/detail/bind_handler.hpp>
15 #include <type_traits>
16 #include <utility>
17
18 namespace boost {
19 namespace beast {
20
21 /** Bind parameters to a completion handler, creating a new handler.
22
23 This function creates a new handler which, when invoked, calls
24 the original handler with the list of bound arguments. Any
25 parameters passed in the invocation will be substituted for
26 placeholders present in the list of bound arguments. Parameters
27 which are not matched to placeholders are silently discarded.
28
29 The passed handler and arguments are forwarded into the returned
30 handler, whose associated allocator and associated executor will
31 will be the same as those of the original handler.
32
33 @par Example
34
35 This function posts the invocation of the specified completion
36 handler with bound arguments:
37
38 @code
39 template <class AsyncReadStream, class ReadHandler>
40 void
41 signal_aborted (AsyncReadStream& stream, ReadHandler&& handler)
42 {
43 net::post(
44 stream.get_executor(),
45 bind_handler (std::forward <ReadHandler> (handler),
46 net::error::operation_aborted, 0));
47 }
48 @endcode
49
50 @param handler The handler to wrap.
51 The implementation takes ownership of the handler by performing a decay-copy.
52
53 @param args A list of arguments to bind to the handler.
54 The arguments are forwarded into the returned object. These
55 arguments may include placeholders, which will operate in
56 a fashion identical to a call to `std::bind`.
57 */
58 template<class Handler, class... Args>
59 #if BOOST_BEAST_DOXYGEN
60 __implementation_defined__
61 #else
62 detail::bind_wrapper<
63 typename std::decay<Handler>::type,
64 typename std::decay<Args>::type...>
65 #endif
66 bind_handler(Handler&& handler, Args&&... args)
67 {
68 return detail::bind_wrapper<
69 typename std::decay<Handler>::type,
70 typename std::decay<Args>::type...>(
71 std::forward<Handler>(handler),
72 std::forward<Args>(args)...);
73 }
74
75 /** Bind parameters to a completion handler, creating a new handler.
76
77 This function creates a new handler which, when invoked, calls
78 the original handler with the list of bound arguments. Any
79 parameters passed in the invocation will be forwarded in
80 the parameter list after the bound arguments.
81
82 The passed handler and arguments are forwarded into the returned
83 handler, whose associated allocator and associated executor will
84 will be the same as those of the original handler.
85
86 @par Example
87
88 This function posts the invocation of the specified completion
89 handler with bound arguments:
90
91 @code
92 template <class AsyncReadStream, class ReadHandler>
93 void
94 signal_eof (AsyncReadStream& stream, ReadHandler&& handler)
95 {
96 net::post(
97 stream.get_executor(),
98 bind_front_handler (std::forward<ReadHandler> (handler),
99 net::error::eof, 0));
100 }
101 @endcode
102
103 @param handler The handler to wrap.
104 The implementation takes ownership of the handler by performing a decay-copy.
105
106 @param args A list of arguments to bind to the handler.
107 The arguments are forwarded into the returned object.
108 */
109 template<class Handler, class... Args>
110 #if BOOST_BEAST_DOXYGEN
111 __implementation_defined__
112 #else
113 auto
114 #endif
115 bind_front_handler(
116 Handler&& handler,
117 Args&&... args) ->
118 detail::bind_front_wrapper<
119 typename std::decay<Handler>::type,
120 typename std::decay<Args>::type...>
121 {
122 return detail::bind_front_wrapper<
123 typename std::decay<Handler>::type,
124 typename std::decay<Args>::type...>(
125 std::forward<Handler>(handler),
126 std::forward<Args>(args)...);
127 }
128
129 } // beast
130 } // boost
131
132 #endif