Clementine
as_operation.hpp
1 //
2 // execution/detail/as_operation.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 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 ASIO_EXECUTION_DETAIL_AS_OPERATION_HPP
12 #define ASIO_EXECUTION_DETAIL_AS_OPERATION_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/detail/memory.hpp"
20 #include "asio/detail/type_traits.hpp"
21 #include "asio/execution/detail/as_invocable.hpp"
22 #include "asio/execution/execute.hpp"
23 #include "asio/execution/set_error.hpp"
24 #include "asio/traits/start_member.hpp"
25 
26 #include "asio/detail/push_options.hpp"
27 
28 namespace asio {
29 namespace execution {
30 namespace detail {
31 
32 template <typename Executor, typename Receiver>
34 {
35  typename remove_cvref<Executor>::type ex_;
36  typename remove_cvref<Receiver>::type receiver_;
37 #if !defined(ASIO_HAS_MOVE)
38  asio::detail::shared_ptr<asio::detail::atomic_count> ref_count_;
39 #endif // !defined(ASIO_HAS_MOVE)
40 
41  template <typename E, typename R>
42  explicit as_operation(ASIO_MOVE_ARG(E) e, ASIO_MOVE_ARG(R) r)
43  : ex_(ASIO_MOVE_CAST(E)(e)),
44  receiver_(ASIO_MOVE_CAST(R)(r))
45 #if !defined(ASIO_HAS_MOVE)
46  , ref_count_(new asio::detail::atomic_count(1))
47 #endif // !defined(ASIO_HAS_MOVE)
48  {
49  }
50 
51  void start() ASIO_NOEXCEPT
52  {
53 #if !defined(ASIO_NO_EXCEPTIONS)
54  try
55  {
56 #endif // !defined(ASIO_NO_EXCEPTIONS)
57  execution::execute(
58  ASIO_MOVE_CAST(typename remove_cvref<Executor>::type)(ex_),
60  Executor>(receiver_
61 #if !defined(ASIO_HAS_MOVE)
62  , ref_count_
63 #endif // !defined(ASIO_HAS_MOVE)
64  ));
65 #if !defined(ASIO_NO_EXCEPTIONS)
66  }
67  catch (...)
68  {
69 #if defined(ASIO_HAS_STD_EXCEPTION_PTR)
70  execution::set_error(
71  ASIO_MOVE_OR_LVALUE(
73  receiver_),
74  std::current_exception());
75 #else // defined(ASIO_HAS_STD_EXCEPTION_PTR)
76  std::terminate();
77 #endif // defined(ASIO_HAS_STD_EXCEPTION_PTR)
78  }
79 #endif // !defined(ASIO_NO_EXCEPTIONS)
80  }
81 };
82 
83 } // namespace detail
84 } // namespace execution
85 namespace traits {
86 
87 #if !defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
88 
89 template <typename Executor, typename Receiver>
90 struct start_member<
91  asio::execution::detail::as_operation<Executor, Receiver> >
92 {
93  ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
94  ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
95  typedef void result_type;
96 };
97 
98 #endif // !defined(ASIO_HAS_DEDUCED_START_MEMBER_TRAIT)
99 
100 } // namespace traits
101 } // namespace asio
102 
103 #include "asio/detail/pop_options.hpp"
104 
105 #endif // ASIO_EXECUTION_DETAIL_AS_OPERATION_HPP
Definition: start_member.hpp:38
Definition: as_invocable.hpp:84
Definition: chrono.h:284
Definition: as_operation.hpp:33
Definition: handler_work.hpp:37
Definition: type_traits.hpp:128
Definition: any_io_executor.hpp:28