ゴミ箱
async_result.hpp
Go to the documentation of this file.
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_ASYNC_COMPLETION_HPP
11 #define BOOST_BEAST_ASYNC_COMPLETION_HPP
12 
13 #include <boost/beast/config.hpp>
15 #include <boost/asio/async_result.hpp>
16 #include <boost/asio/handler_type.hpp>
17 #include <type_traits>
18 #include <utility>
19 
20 namespace boost {
21 namespace beast {
22 
74 template<class CompletionToken, class Signature>
76 {
77  BOOST_STATIC_ASSERT(
78  ! std::is_reference<CompletionToken>::value);
79 
80  boost::asio::async_result<typename
81  boost::asio::handler_type<CompletionToken,
82  Signature>::type> impl_;
83 
84  async_result(async_result const&) = delete;
85  async_result& operator=(async_result const&) = delete;
86 
87 public:
91  CompletionToken, Signature>::type;
92 
94  using return_type =
95  typename boost::asio::async_result<
97 
105  explicit
107  : impl_(h)
108  {
109  }
110 
113  get()
114  {
115  return impl_.get();
116  }
117 };
118 
150 template<class CompletionToken, class Signature>
152 {
157  using completion_handler_type = typename async_result<
158  typename std::decay<CompletionToken>::type,
160 
171  explicit
172  async_completion(CompletionToken& token)
173  : completion_handler(static_cast<typename std::conditional<
174  std::is_same<CompletionToken, completion_handler_type>::value,
175  completion_handler_type&, CompletionToken&&>::type>(token))
176  , result(completion_handler)
177  {
178  // CompletionToken is not invokable with the given signature
179  static_assert(is_completion_handler<
180  completion_handler_type, Signature>::value,
181  "CompletionToken requirements not met: signature mismatch");
182  }
183 
185  typename std::conditional<std::is_same<
186  CompletionToken, completion_handler_type>::value,
188  completion_handler_type
190 
192  async_result<typename std::decay<
193  CompletionToken>::type, Signature> result;
194 };
195 
196 template<class CompletionToken, typename Signature>
197 using handler_type = typename beast::async_result<
198  typename std::decay<CompletionToken>::type,
200 
201 template<class CompletionToken, typename Signature>
202 using async_return_type = typename beast::async_result<
203  typename std::decay<CompletionToken>::type,
204  Signature>::return_type;
205 
206 } // beast
207 } // boost
208 
209 #endif
Definition: async_result.hpp:20
async_result(completion_handler_type &h)
Definition: async_result.hpp:106
STL namespace.
typename async_result< typename std::decay< CompletionToken >::type, Signature >::completion_handler_type completion_handler_type
Definition: async_result.hpp:159
async_result< typename std::decay< CompletionToken >::type, Signature > result
The return value of the asynchronous initiation function.
Definition: async_result.hpp:193
typename beast::async_result< typename std::decay< CompletionToken >::type, Signature >::completion_handler_type handler_type
Definition: async_result.hpp:199
async_completion(CompletionToken &token)
Definition: async_result.hpp:172
std::integral_constant< bool, std::is_copy_constructible< typename std::decay< T >::type >::value &&detail::is_invocable< T, Signature >::value > is_completion_handler
Definition: type_traits.hpp:203
typename boost::asio::async_result< completion_handler_type >::type return_type
The return type of the initiating function.
Definition: async_result.hpp:96
typename boost::asio::handler_type< CompletionToken, Signature >::type completion_handler_type
The concrete completion handler type for the specific signature.
Definition: async_result.hpp:91
Definition: async_result.hpp:75
typename beast::async_result< typename std::decay< CompletionToken >::type, Signature >::return_type async_return_type
Definition: async_result.hpp:204
Definition: async_result.hpp:151
std::conditional< std::is_same< CompletionToken, completion_handler_type >::value, completion_handler_type &, completion_handler_type >::type completion_handler
The final completion handler, callable with the specified signature.
Definition: async_result.hpp:189