• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // async_result.hpp
3 // ~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 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 ARCHETYPES_ASYNC_RESULT_HPP
12 #define ARCHETYPES_ASYNC_RESULT_HPP
13 
14 #include <boost/asio/async_result.hpp>
15 
16 namespace archetypes {
17 
18 struct lazy_handler
19 {
20 };
21 
22 template <typename Signature>
23 struct concrete_handler;
24 
25 template <typename R, typename Arg1>
26 struct concrete_handler<R(Arg1)>
27 {
concrete_handlerarchetypes::concrete_handler28   concrete_handler(lazy_handler)
29   {
30   }
31 
operator ()archetypes::concrete_handler32   void operator()(typename boost::asio::decay<Arg1>::type)
33   {
34   }
35 
36 #if defined(BOOST_ASIO_HAS_MOVE)
concrete_handlerarchetypes::concrete_handler37   concrete_handler(concrete_handler&&) {}
38 private:
39   concrete_handler(const concrete_handler&);
40 #endif // defined(BOOST_ASIO_HAS_MOVE)
41 };
42 
43 template <typename R, typename Arg1, typename Arg2>
44 struct concrete_handler<R(Arg1, Arg2)>
45 {
concrete_handlerarchetypes::concrete_handler46   concrete_handler(lazy_handler)
47   {
48   }
49 
operator ()archetypes::concrete_handler50   void operator()(typename boost::asio::decay<Arg1>::type, typename boost::asio::decay<Arg2>::type)
51   {
52   }
53 
54 #if defined(BOOST_ASIO_HAS_MOVE)
concrete_handlerarchetypes::concrete_handler55   concrete_handler(concrete_handler&&) {}
56 private:
57   concrete_handler(const concrete_handler&);
58 #endif // defined(BOOST_ASIO_HAS_MOVE)
59 };
60 
61 } // namespace archetypes
62 
63 namespace boost {
64 namespace asio {
65 
66 template <typename Signature>
67 class async_result<archetypes::lazy_handler, Signature>
68 {
69 public:
70   // The concrete completion handler type.
71   typedef archetypes::concrete_handler<Signature> completion_handler_type;
72 
73   // The return type of the initiating function.
74   typedef int return_type;
75 
76   // Construct an async_result from a given handler.
async_result(completion_handler_type &)77   explicit async_result(completion_handler_type&)
78   {
79   }
80 
81   // Obtain the value to be returned from the initiating function.
get()82   return_type get()
83   {
84     return 42;
85   }
86 
87 private:
88   // Disallow copying and assignment.
89   async_result(const async_result&) BOOST_ASIO_DELETED;
90   async_result& operator=(const async_result&) BOOST_ASIO_DELETED;
91 };
92 
93 } // namespace asio
94 } // namespace boost
95 
96 #endif // ARCHETYPES_ASYNC_RESULT_HPP
97