From 8eba94f40d370363887fa04886699fa5bffc2adb Mon Sep 17 00:00:00 2001 From: zerodefect Date: Thu, 25 Feb 2021 11:24:44 +0000 Subject: [PATCH] Add explicit move constructor / move assignment for task in shared_task. Builds with C++20. --- include/async++/task.h | 11 +++++++++++ include/async++/task_base.h | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/async++/task.h b/include/async++/task.h index 7735c30..597d3e3 100644 --- a/include/async++/task.h +++ b/include/async++/task.h @@ -294,6 +294,17 @@ class shared_task: public detail::basic_task { // Movable and copyable shared_task() = default; + // Move constructor for task + shared_task(task&& other) LIBASYNC_NOEXCEPT + : detail::basic_task(std::move(other)) {} + + // Move-assignment for task + shared_task& operator=(task&& other) LIBASYNC_NOEXCEPT + { + detail::basic_task::operator=(std::move(other)); + return *this; + } + // Get the result of the task get_result get() const { diff --git a/include/async++/task_base.h b/include/async++/task_base.h index 2f16e7e..595f31c 100644 --- a/include/async++/task_base.h +++ b/include/async++/task_base.h @@ -65,13 +65,13 @@ struct LIBASYNC_CACHELINE_ALIGN task_base: public ref_count_base state; // Whether get_task() was already called on an event_task - bool event_task_got_task; + bool event_task_got_task{}; // Vector of continuations continuation_vector continuations; // Virtual function table used for dynamic dispatch - const task_base_vtable* vtable; + const task_base_vtable* vtable{}; // Use aligned memory allocation static void* operator new(std::size_t size)