11 #ifndef ASIO_DETAIL_EXECUTOR_FUNCTION_HPP 12 #define ASIO_DETAIL_EXECUTOR_FUNCTION_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 19 #include "asio/detail/handler_alloc_helpers.hpp" 20 #include "asio/detail/handler_invoke_helpers.hpp" 21 #include "asio/detail/memory.hpp" 23 #include "asio/detail/push_options.hpp" 28 #if defined(ASIO_HAS_MOVE) 31 class executor_function
34 template <
typename F,
typename Alloc>
35 explicit executor_function(F f,
const Alloc& a)
38 typedef impl<F, Alloc> impl_type;
39 typename impl_type::ptr p = {
40 detail::addressof(a), impl_type::ptr::allocate(a), 0 };
41 impl_ =
new (p.v) impl_type(ASIO_MOVE_CAST(F)(f), a);
45 executor_function(executor_function&& other) ASIO_NOEXCEPT
54 impl_->complete_(impl_,
false);
63 i->complete_(i,
true);
71 void (*complete_)(impl_base*, bool);
75 template <
typename Function,
typename Alloc>
76 struct impl : impl_base
78 ASIO_DEFINE_TAGGED_HANDLER_ALLOCATOR_PTR(
79 thread_info_base::executor_function_tag, impl);
82 impl(ASIO_MOVE_ARG(F) f,
const Alloc& a)
83 : function_(ASIO_MOVE_CAST(F)(f)),
86 complete_ = &executor_function::complete<Function, Alloc>;
94 template <
typename Function,
typename Alloc>
95 static void complete(impl_base* base,
bool call)
98 impl<Function, Alloc>* i(
static_cast<impl<Function, Alloc>*
>(base));
100 typename impl<Function, Alloc>::ptr p = {
109 Function
function(ASIO_MOVE_CAST(Function)(i->function_));
115 asio_handler_invoke_helpers::invoke(
function,
function);
122 #else // defined(ASIO_HAS_MOVE) 128 template <
typename F,
typename Alloc>
130 : impl_(
new impl<
typename decay<F>::type>(f))
136 impl_->complete_(impl_.get());
143 void (*complete_)(impl_base*);
147 template <
typename F>
148 struct impl : impl_base
153 complete_ = &executor_function::complete<F>;
160 template <
typename F>
161 static void complete(impl_base* i)
163 static_cast<impl<F>*
>(i)->function_();
166 shared_ptr<impl_base> impl_;
169 #endif // defined(ASIO_HAS_MOVE) 175 template <
typename F>
177 : complete_(&executor_function_view::complete<F>),
184 complete_(function_);
189 template <
typename F>
190 static void complete(
void* f)
192 (*
static_cast<F*
>(f))();
195 void (*complete_)(
void*);
202 #include "asio/detail/pop_options.hpp" 204 #endif // ASIO_DETAIL_EXECUTOR_FUNCTION_HPP Definition: allocator.hpp:17
Definition: executor_function.hpp:125
Definition: executor_function.hpp:172
Definition: any_io_executor.hpp:28