1//
2// async_result.hpp
3// ~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2024 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#include <boost/asio/system_executor.hpp>
16
17namespace archetypes {
18
19struct immediate_handler
20{
21};
22
23struct lazy_handler
24{
25};
26
27template <typename Signature>
28struct concrete_handler;
29
30template <typename R, typename Arg1>
31struct concrete_handler<R(Arg1)>
32{
33 concrete_handler()
34 {
35 }
36
37 void operator()(typename boost::asio::decay<Arg1>::type)
38 {
39 }
40
41 concrete_handler(concrete_handler&&) {}
42private:
43 concrete_handler(const concrete_handler&);
44};
45
46template <typename R, typename Arg1, typename Arg2>
47struct concrete_handler<R(Arg1, Arg2)>
48{
49 concrete_handler()
50 {
51 }
52
53 void operator()(typename boost::asio::decay<Arg1>::type,
54 typename boost::asio::decay<Arg2>::type)
55 {
56 }
57};
58
59template <typename Signature>
60struct immediate_concrete_handler : concrete_handler<Signature>
61{
62 typedef boost::asio::system_executor immediate_executor_type;
63
64 immediate_concrete_handler(immediate_handler)
65 {
66 }
67
68 immediate_executor_type get_immediate_executor() const noexcept
69 {
70 return immediate_executor_type();
71 }
72
73 immediate_concrete_handler(immediate_concrete_handler&&) {}
74private:
75 immediate_concrete_handler(const immediate_concrete_handler&);
76};
77
78template <typename Signature>
79struct lazy_concrete_handler : concrete_handler<Signature>
80{
81 lazy_concrete_handler(lazy_handler)
82 {
83 }
84
85 lazy_concrete_handler(lazy_concrete_handler&&) {}
86private:
87 lazy_concrete_handler(const lazy_concrete_handler&);
88};
89
90} // namespace archetypes
91
92namespace boost {
93namespace asio {
94
95template <typename Signature>
96class async_result<archetypes::immediate_handler, Signature>
97{
98public:
99 // The concrete completion handler type.
100 typedef archetypes::immediate_concrete_handler<Signature>
101 completion_handler_type;
102
103 // The return type of the initiating function.
104 typedef void return_type;
105
106 // Construct an async_result from a given handler.
107 explicit async_result(completion_handler_type&)
108 {
109 }
110
111 // Obtain the value to be returned from the initiating function.
112 void get()
113 {
114 }
115
116private:
117 // Disallow copying and assignment.
118 async_result(const async_result&) = delete;
119 async_result& operator=(const async_result&) = delete;
120};
121
122template <typename Signature>
123class async_result<archetypes::lazy_handler, Signature>
124{
125public:
126 // The concrete completion handler type.
127 typedef archetypes::lazy_concrete_handler<Signature> completion_handler_type;
128
129 // The return type of the initiating function.
130 typedef int return_type;
131
132 // Construct an async_result from a given handler.
133 explicit async_result(completion_handler_type&)
134 {
135 }
136
137 // Obtain the value to be returned from the initiating function.
138 return_type get()
139 {
140 return 42;
141 }
142
143private:
144 // Disallow copying and assignment.
145 async_result(const async_result&) = delete;
146 async_result& operator=(const async_result&) = delete;
147};
148
149} // namespace asio
150} // namespace boost
151
152#endif // ARCHETYPES_ASYNC_RESULT_HPP
153

source code of boost/libs/asio/test/archetypes/async_result.hpp