]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // |
2 | // execution/detail/as_receiver.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
1e59de90 | 5 | // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
20effc67 TL |
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 BOOST_ASIO_EXECUTION_DETAIL_AS_RECEIVER_HPP | |
12 | #define BOOST_ASIO_EXECUTION_DETAIL_AS_RECEIVER_HPP | |
13 | ||
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) | |
15 | # pragma once | |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) | |
17 | ||
18 | #include <boost/asio/detail/config.hpp> | |
19 | #include <boost/asio/detail/type_traits.hpp> | |
20 | #include <boost/asio/traits/set_done_member.hpp> | |
21 | #include <boost/asio/traits/set_error_member.hpp> | |
22 | #include <boost/asio/traits/set_value_member.hpp> | |
23 | ||
24 | #include <boost/asio/detail/push_options.hpp> | |
25 | ||
26 | namespace boost { | |
27 | namespace asio { | |
28 | namespace execution { | |
29 | namespace detail { | |
30 | ||
31 | template <typename Function, typename> | |
32 | struct as_receiver | |
33 | { | |
34 | Function f_; | |
35 | ||
36 | template <typename F> | |
37 | explicit as_receiver(BOOST_ASIO_MOVE_ARG(F) f, int) | |
38 | : f_(BOOST_ASIO_MOVE_CAST(F)(f)) | |
39 | { | |
40 | } | |
41 | ||
42 | #if defined(BOOST_ASIO_MSVC) && defined(BOOST_ASIO_HAS_MOVE) | |
43 | as_receiver(as_receiver&& other) | |
44 | : f_(BOOST_ASIO_MOVE_CAST(Function)(other.f_)) | |
45 | { | |
46 | } | |
47 | #endif // defined(BOOST_ASIO_MSVC) && defined(BOOST_ASIO_HAS_MOVE) | |
48 | ||
49 | void set_value() | |
50 | BOOST_ASIO_NOEXCEPT_IF(noexcept(declval<Function&>()())) | |
51 | { | |
52 | f_(); | |
53 | } | |
54 | ||
55 | template <typename E> | |
56 | void set_error(E) BOOST_ASIO_NOEXCEPT | |
57 | { | |
58 | std::terminate(); | |
59 | } | |
60 | ||
61 | void set_done() BOOST_ASIO_NOEXCEPT | |
62 | { | |
63 | } | |
64 | }; | |
65 | ||
66 | template <typename T> | |
67 | struct is_as_receiver : false_type | |
68 | { | |
69 | }; | |
70 | ||
71 | template <typename Function, typename T> | |
72 | struct is_as_receiver<as_receiver<Function, T> > : true_type | |
73 | { | |
74 | }; | |
75 | ||
76 | } // namespace detail | |
77 | } // namespace execution | |
78 | namespace traits { | |
79 | ||
80 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT) | |
81 | ||
82 | template <typename Function, typename T> | |
83 | struct set_value_member< | |
84 | boost::asio::execution::detail::as_receiver<Function, T>, void()> | |
85 | { | |
86 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
87 | #if defined(BOOST_ASIO_HAS_NOEXCEPT) | |
88 | BOOST_ASIO_STATIC_CONSTEXPR(bool, | |
89 | is_noexcept = noexcept(declval<Function&>()())); | |
90 | #else // defined(BOOST_ASIO_HAS_NOEXCEPT) | |
91 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
92 | #endif // defined(BOOST_ASIO_HAS_NOEXCEPT) | |
93 | typedef void result_type; | |
94 | }; | |
95 | ||
96 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT) | |
97 | ||
98 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
99 | ||
100 | template <typename Function, typename T, typename E> | |
101 | struct set_error_member< | |
102 | boost::asio::execution::detail::as_receiver<Function, T>, E> | |
103 | { | |
104 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
105 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
106 | typedef void result_type; | |
107 | }; | |
108 | ||
109 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) | |
110 | ||
111 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
112 | ||
113 | template <typename Function, typename T> | |
114 | struct set_done_member< | |
115 | boost::asio::execution::detail::as_receiver<Function, T> > | |
116 | { | |
117 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
118 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
119 | typedef void result_type; | |
120 | }; | |
121 | ||
122 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
123 | ||
124 | } // namespace traits | |
125 | } // namespace asio | |
126 | } // namespace boost | |
127 | ||
128 | #include <boost/asio/detail/pop_options.hpp> | |
129 | ||
130 | #endif // BOOST_ASIO_EXECUTION_DETAIL_AS_RECEIVER_HPP |