Skip to content

Commit

Permalink
Fix bind_cancellation_slot to not require async_result::return_type.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Aug 1, 2023
1 parent f042b0b commit 9009036
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
34 changes: 25 additions & 9 deletions include/boost/asio/bind_cancellation_slot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,40 @@ namespace detail {

template <typename TargetAsyncResult,
typename CancellationSlot, typename = void>
struct cancellation_slot_binder_async_result_completion_handler_type
class cancellation_slot_binder_completion_handler_async_result
{
public:
template <typename T>
explicit cancellation_slot_binder_completion_handler_async_result(T&)
{
}
};

template <typename TargetAsyncResult, typename CancellationSlot>
struct cancellation_slot_binder_async_result_completion_handler_type<
class cancellation_slot_binder_completion_handler_async_result<
TargetAsyncResult, CancellationSlot,
typename void_type<
typename TargetAsyncResult::completion_handler_type
>::type>
{
public:
typedef cancellation_slot_binder<
typename TargetAsyncResult::completion_handler_type, CancellationSlot>
completion_handler_type;

explicit cancellation_slot_binder_completion_handler_async_result(
typename TargetAsyncResult::completion_handler_type& handler)
: target_(handler)
{
}

typename TargetAsyncResult::return_type get()
{
return target_.get();
}

private:
TargetAsyncResult target_;
};

template <typename TargetAsyncResult, typename = void>
Expand All @@ -509,22 +529,18 @@ struct cancellation_slot_binder_async_result_return_type<

template <typename T, typename CancellationSlot, typename Signature>
class async_result<cancellation_slot_binder<T, CancellationSlot>, Signature> :
public detail::cancellation_slot_binder_async_result_completion_handler_type<
public detail::cancellation_slot_binder_completion_handler_async_result<
async_result<T, Signature>, CancellationSlot>,
public detail::cancellation_slot_binder_async_result_return_type<
async_result<T, Signature> >
{
public:
explicit async_result(cancellation_slot_binder<T, CancellationSlot>& b)
: target_(b.get())
: detail::cancellation_slot_binder_completion_handler_async_result<
async_result<T, Signature>, CancellationSlot>(b.get())
{
}

typename async_result<T, Signature>::return_type get()
{
return target_.get();
}

template <typename Initiation>
struct init_wrapper
{
Expand Down
2 changes: 2 additions & 0 deletions test/bind_cancellation_slot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ template <>
class async_result<incrementer_token_v2, void(boost::system::error_code)>
{
public:
#if !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION)
typedef void return_type;
#endif // !defined(BOOST_ASIO_HAS_RETURN_TYPE_DEDUCTION)

#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)

Expand Down

0 comments on commit 9009036

Please sign in to comment.