@@ -69,11 +69,11 @@ class continuation_base {
6969class future_shared_state_base {
7070 public:
7171 future_shared_state_base () : future_shared_state_base([] {}) {}
72- future_shared_state_base (std::function<void ()> cancellation_callback)
72+ explicit future_shared_state_base (std::function<void ()> cancellation_callback)
7373 : mu_(),
7474 cv_(),
7575 current_state_(state::not_ready),
76- cancellation_callback_(cancellation_callback) {}
76+ cancellation_callback_(std::move( cancellation_callback) ) {}
7777 // / Return true if the shared state has a value or an exception.
7878 bool is_ready () const {
7979 std::unique_lock<std::mutex> lk (mu_);
@@ -204,6 +204,10 @@ class future_shared_state_base {
204204 continuation_ = std::move (c);
205205 }
206206
207+ std::function<void ()> extract_cancellation_callback () {
208+ return std::move (cancellation_callback_);
209+ }
210+
207211 // Try to cancel the task by invoking the cancellation_callback.
208212 bool cancel () {
209213 if (!cancellable ()) {
@@ -330,8 +334,8 @@ template <typename T>
330334class future_shared_state final : private future_shared_state_base {
331335 public:
332336 future_shared_state () : future_shared_state_base(), buffer_() {}
333- future_shared_state (std::function<void ()> cancellation_callback)
334- : future_shared_state_base(cancellation_callback), buffer_() {}
337+ explicit future_shared_state (std::function<void ()> cancellation_callback)
338+ : future_shared_state_base(std::move( cancellation_callback) ), buffer_() {}
335339 ~future_shared_state () {
336340 if (current_state_ == state::has_value) {
337341 // Recall that state::has_value is a terminal state, once a value is
@@ -345,6 +349,7 @@ class future_shared_state final : private future_shared_state_base {
345349
346350 using future_shared_state_base::abandon;
347351 using future_shared_state_base::cancel;
352+ using future_shared_state_base::extract_cancellation_callback;
348353 using future_shared_state_base::is_ready;
349354 using future_shared_state_base::set_continuation;
350355 using future_shared_state_base::set_exception;
@@ -468,11 +473,12 @@ template <>
468473class future_shared_state <void > final : private future_shared_state_base {
469474 public:
470475 future_shared_state () : future_shared_state_base() {}
471- future_shared_state (std::function<void ()> cancellation_callback)
472- : future_shared_state_base(cancellation_callback) {}
476+ explicit future_shared_state (std::function<void ()> cancellation_callback)
477+ : future_shared_state_base(std::move( cancellation_callback) ) {}
473478
474479 using future_shared_state_base::abandon;
475480 using future_shared_state_base::cancel;
481+ using future_shared_state_base::extract_cancellation_callback;
476482 using future_shared_state_base::is_ready;
477483 using future_shared_state_base::set_continuation;
478484 using future_shared_state_base::set_exception;
@@ -666,7 +672,8 @@ struct continuation : public continuation_base {
666672 continuation (Functor&& f, std::shared_ptr<input_shared_state_t > s)
667673 : functor(std::move(f)),
668674 input (std::move(s)),
669- output(std::make_shared<future_shared_state<result_t >>()) {}
675+ output(std::make_shared<future_shared_state<result_t >>(
676+ input.lock()->extract_cancellation_callback())) {}
670677
671678 continuation (Functor&& f, std::shared_ptr<input_shared_state_t > s,
672679 std::shared_ptr<output_shared_state_t > o)
@@ -721,7 +728,8 @@ struct unwrapping_continuation : public continuation_base {
721728 : functor(std::move(f)),
722729 input (std::move(s)),
723730 intermediate(),
724- output(std::make_shared<output_shared_state_t >()) {}
731+ output(std::make_shared<output_shared_state_t >(
732+ input.lock()->extract_cancellation_callback())) {}
725733
726734 void execute () override {
727735 auto tmp = input.lock ();
0 commit comments