From 066812039873991416f04ebb3c051ac8cb669d14 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 20 Oct 2020 17:34:27 -0400 Subject: cm::optional: Fix move assignment --- Utilities/std/cm/optional | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'Utilities') diff --git a/Utilities/std/cm/optional b/Utilities/std/cm/optional index 9a5d840766..4eb7f27d84 100644 --- a/Utilities/std/cm/optional +++ b/Utilities/std/cm/optional @@ -68,16 +68,22 @@ public: optional& operator=(nullopt_t) noexcept; optional& operator=(const optional& other); - optional& operator=(optional&& other) noexcept; - template < - typename U = T, - typename = typename std::enable_if< - !std::is_same::type, cm::optional>::value && - std::is_constructible::value && std::is_assignable::value && + template + typename std::enable_if::value && + std::is_assignable::value, + optional&>::type + operator=(optional&& other) noexcept; + + template + typename std::enable_if< + !std::is_same::type, cm::optional>::value && + std::is_constructible::value && + std::is_assignable::value && (!std::is_scalar::value || - !std::is_same::type, T>::value)>::type> - optional& operator=(U&& v); + !std::is_same::type, T>::value), + optional&>::type + operator=(U&& v); const T* operator->() const; T* operator->(); @@ -140,13 +146,17 @@ optional::optional(nullopt_t) noexcept template optional::optional(const optional& other) { - *this = other; + if (other.has_value()) { + this->emplace(*other); + } } template optional::optional(optional&& other) noexcept { - *this = std::move(other); + if (other.has_value()) { + this->emplace(std::move(*other)); + } } template @@ -192,7 +202,11 @@ optional& optional::operator=(const optional& other) } template -optional& optional::operator=(optional&& other) noexcept +template +typename std::enable_if::value && + std::is_assignable::value, + optional&>::type +optional::operator=(optional&& other) noexcept { if (other.has_value()) { if (this->has_value()) { @@ -207,8 +221,15 @@ optional& optional::operator=(optional&& other) noexcept } template -template -optional& optional::operator=(U&& v) +template +typename std::enable_if< + !std::is_same::type, cm::optional>::value && + std::is_constructible::value && + std::is_assignable::value && + (!std::is_scalar::value || + !std::is_same::type, T>::value), + optional&>::type +optional::operator=(U&& v) { if (this->has_value()) { this->value() = v; -- cgit v1.2.1