From 143ad160518fed792f7616c2c93ab8101d130736 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 Jul 2019 12:34:24 -0700 Subject: Use uninitialized_copy/move for optionals --- common/aloptional.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'common') diff --git a/common/aloptional.h b/common/aloptional.h index 6843a8cd..443da0b4 100644 --- a/common/aloptional.h +++ b/common/aloptional.h @@ -26,20 +26,18 @@ public: optional(const optional &rhs) : mHasValue{rhs.mHasValue} { if(mHasValue) - new (std::addressof(mValue)) T{*rhs}; + std::uninitialized_copy_n(std::addressof(*rhs), 1, std::addressof(mValue)); } template::value)> optional(optional&& rhs) : mHasValue{rhs.mHasValue} { if(mHasValue) - new (std::addressof(mValue)) T{std::move(*rhs)}; + al::uninitialized_move_n(std::addressof(*rhs), 1, std::addressof(mValue)); } template explicit optional(in_place_t, Args&& ...args) : mHasValue{true}, mValue{std::forward(args)...} { } - template::value)> - optional(const optional&) noexcept = delete; ~optional() { reset(); } optional& operator=(nullopt_t) noexcept { reset(); return *this; } @@ -52,7 +50,7 @@ public: mValue = *rhs; else { - new (std::addressof(mValue)) T{*rhs}; + std::uninitialized_copy_n(std::addressof(*rhs), 1, std::addressof(mValue)); mHasValue = true; } return *this; @@ -66,13 +64,11 @@ public: mValue = std::move(*rhs); else { - new (std::addressof(mValue)) T{std::move(*rhs)}; + al::uninitialized_move_n(std::addressof(*rhs), 1, std::addressof(mValue)); mHasValue = true; } return *this; } - template::value || !std::is_copy_assignable::value)> - optional& operator=(const optional&) = delete; const T* operator->() const { return std::addressof(mValue); } T* operator->() { return std::addressof(mValue); } -- cgit v1.2.3