From ac5634fdba34c6aae0c2b9d6fc30b5158eeb2e1b Mon Sep 17 00:00:00 2001 From: Matthew Schafer Date: Sat, 13 Aug 2022 12:56:09 +1000 Subject: [PATCH] Replace deprecated std::aligned_storage with alternative --- include/async++/task_base.h | 10 +++++----- src/singleton.h | 2 +- src/task_wait_event.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/async++/task_base.h b/include/async++/task_base.h index d1943fe..377ac8f 100644 --- a/include/async++/task_base.h +++ b/include/async++/task_base.h @@ -166,8 +166,8 @@ struct task_base_deleter { template struct task_result_holder: public task_base { union { - typename std::aligned_storage::value>::type result; - std::aligned_storage::value>::type except; + alignas(Result) std::uint8_t result[sizeof(Result)]; + alignas(std::exception_ptr) std::uint8_t except[sizeof(std::exception_ptr)]; // Scheduler that should be used to schedule this task. The scheduler // type has been erased and is held by vtable->schedule. @@ -208,7 +208,7 @@ struct task_result_holder: public task_base { union { // Store as pointer internally Result* result; - std::aligned_storage::value>::type except; + alignas(std::exception_ptr) std::uint8_t except[sizeof(std::exception_ptr)]; void* sched; }; @@ -233,7 +233,7 @@ struct task_result_holder: public task_base { template<> struct task_result_holder: public task_base { union { - std::aligned_storage::value>::type except; + alignas(std::exception_ptr) std::uint8_t except[sizeof(std::exception_ptr)]; void* sched; }; @@ -344,7 +344,7 @@ struct func_base::value>::type // Class to hold a function object and initialize/destroy it at any time template struct func_holder { - typename std::aligned_storage::value>::type func; + alignas(Func) std::uint8_t func[sizeof(Func)]; Func& get_func() { diff --git a/src/singleton.h b/src/singleton.h index 45d1457..869800d 100644 --- a/src/singleton.h +++ b/src/singleton.h @@ -39,7 +39,7 @@ template class singleton { std::mutex lock; std::atomic init_flag; - typename std::aligned_storage::value>::type storage; + alignas(T) std::uint8_t storage[sizeof(T)]; static singleton instance; diff --git a/src/task_wait_event.h b/src/task_wait_event.h index 7a28211..2f10ff8 100644 --- a/src/task_wait_event.h +++ b/src/task_wait_event.h @@ -35,8 +35,8 @@ enum wait_type { // // The event object is lazily initialized to avoid unnecessary API calls. class task_wait_event { - std::aligned_storage::value>::type m; - std::aligned_storage::value>::type c; + alignas(std::mutex) std::uint8_t m[sizeof(std::mutex)]; + alignas(std::condition_variable) std::uint8_t c[sizeof(std::condition_variable)]; int event_mask; bool initialized;