]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/core/detail/bind_handler.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / core / detail / bind_handler.hpp
1 //
2 // Copyright (c) 2013-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
8 #ifndef BEAST_BIND_DETAIL_HANDLER_HPP
9 #define BEAST_BIND_DETAIL_HANDLER_HPP
10
11 #include <beast/core/handler_helpers.hpp>
12 #include <beast/core/detail/integer_sequence.hpp>
13 #include <utility>
14
15 namespace beast {
16 namespace detail {
17
18 /* Nullary handler that calls Handler with bound arguments.
19
20 The bound handler provides the same io_service execution
21 guarantees as the original handler.
22 */
23 template<class Handler, class... Args>
24 class bound_handler
25 {
26 private:
27 using args_type = std::tuple<
28 typename std::decay<Args>::type...>;
29
30 Handler h_;
31 args_type args_;
32
33 template<class Tuple, std::size_t... S>
34 static void invoke(Handler& h, Tuple& args,
35 index_sequence<S...>)
36 {
37 h(std::get<S>(args)...);
38 }
39
40 public:
41 using result_type = void;
42
43 template<class DeducedHandler>
44 explicit
45 bound_handler(
46 DeducedHandler&& handler, Args&&... args)
47 : h_(std::forward<DeducedHandler>(handler))
48 , args_(std::forward<Args>(args)...)
49 {
50 }
51
52 void
53 operator()()
54 {
55 invoke(h_, args_,
56 index_sequence_for<Args...>());
57 }
58
59 void
60 operator()() const
61 {
62 invoke(h_, args_,
63 index_sequence_for<Args...>());
64 }
65
66 friend
67 void*
68 asio_handler_allocate(
69 std::size_t size, bound_handler* h)
70 {
71 return beast_asio_helpers::
72 allocate(size, h->h_);
73 }
74
75 friend
76 void
77 asio_handler_deallocate(
78 void* p, std::size_t size, bound_handler* h)
79 {
80 beast_asio_helpers::
81 deallocate(p, size, h->h_);
82 }
83
84 friend
85 bool
86 asio_handler_is_continuation(bound_handler* h)
87 {
88 return beast_asio_helpers::
89 is_continuation (h->h_);
90 }
91
92 template<class F>
93 friend
94 void
95 asio_handler_invoke(F&& f, bound_handler* h)
96 {
97 beast_asio_helpers::
98 invoke(f, h->h_);
99 }
100 };
101
102 } // detail
103 } // beast
104
105 #include <functional>
106
107 namespace std {
108 template<class Handler, class... Args>
109 void
110 bind(beast::detail::bound_handler<
111 Handler, Args...>, ...) = delete;
112 } // std
113
114 #endif