aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-07-01 12:34:24 -0700
committerChris Robinson <[email protected]>2019-07-01 12:34:24 -0700
commit143ad160518fed792f7616c2c93ab8101d130736 (patch)
treeeb30752ee41813e9a39cc2bb3864df25ebbe970f /common
parentc9ffa9d466f5d0a24c9f51f430b19410abdf868f (diff)
Use uninitialized_copy/move for optionals
Diffstat (limited to 'common')
-rw-r--r--common/aloptional.h12
1 files changed, 4 insertions, 8 deletions
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<REQUIRES(std::is_move_constructible<T>::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<typename... Args>
explicit optional(in_place_t, Args&& ...args)
: mHasValue{true}, mValue{std::forward<Args>(args)...}
{ }
- template<REQUIRES(!std::is_copy_constructible<T>::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<REQUIRES(!std::is_copy_constructible<T>::value || !std::is_copy_assignable<T>::value)>
- optional& operator=(const optional&) = delete;
const T* operator->() const { return std::addressof(mValue); }
T* operator->() { return std::addressof(mValue); }