summaryrefslogtreecommitdiffstats
path: root/Utilities
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-10-20 21:34:27 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2020-10-21 18:23:43 (GMT)
commit066812039873991416f04ebb3c051ac8cb669d14 (patch)
treeda8180577785051d52da309f99147c96445eb969 /Utilities
parentccd313a074657f9ebf9ae6a4c9b71587000878af (diff)
downloadCMake-066812039873991416f04ebb3c051ac8cb669d14.zip
CMake-066812039873991416f04ebb3c051ac8cb669d14.tar.gz
CMake-066812039873991416f04ebb3c051ac8cb669d14.tar.bz2
cm::optional: Fix move assignment
Diffstat (limited to 'Utilities')
-rw-r--r--Utilities/std/cm/optional47
1 files changed, 34 insertions, 13 deletions
diff --git a/Utilities/std/cm/optional b/Utilities/std/cm/optional
index 9a5d840..4eb7f27 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<typename std::decay<U>::type, cm::optional<T>>::value &&
- std::is_constructible<T, U>::value && std::is_assignable<T&, U>::value &&
+ template <typename U = T>
+ typename std::enable_if<std::is_constructible<T, U&&>::value &&
+ std::is_assignable<T&, U&&>::value,
+ optional&>::type
+ operator=(optional<U>&& other) noexcept;
+
+ template <typename U = T>
+ typename std::enable_if<
+ !std::is_same<typename std::decay<U>::type, cm::optional<T>>::value &&
+ std::is_constructible<T, U&&>::value &&
+ std::is_assignable<T&, U&&>::value &&
(!std::is_scalar<T>::value ||
- !std::is_same<typename std::decay<U>::type, T>::value)>::type>
- optional& operator=(U&& v);
+ !std::is_same<typename std::decay<U>::type, T>::value),
+ optional&>::type
+ operator=(U&& v);
const T* operator->() const;
T* operator->();
@@ -140,13 +146,17 @@ optional<T>::optional(nullopt_t) noexcept
template <typename T>
optional<T>::optional(const optional& other)
{
- *this = other;
+ if (other.has_value()) {
+ this->emplace(*other);
+ }
}
template <typename T>
optional<T>::optional(optional&& other) noexcept
{
- *this = std::move(other);
+ if (other.has_value()) {
+ this->emplace(std::move(*other));
+ }
}
template <typename T>
@@ -192,7 +202,11 @@ optional<T>& optional<T>::operator=(const optional& other)
}
template <typename T>
-optional<T>& optional<T>::operator=(optional&& other) noexcept
+template <typename U>
+typename std::enable_if<std::is_constructible<T, U&&>::value &&
+ std::is_assignable<T&, U&&>::value,
+ optional<T>&>::type
+optional<T>::operator=(optional<U>&& other) noexcept
{
if (other.has_value()) {
if (this->has_value()) {
@@ -207,8 +221,15 @@ optional<T>& optional<T>::operator=(optional&& other) noexcept
}
template <typename T>
-template <typename U, typename>
-optional<T>& optional<T>::operator=(U&& v)
+template <typename U>
+typename std::enable_if<
+ !std::is_same<typename std::decay<U>::type, cm::optional<T>>::value &&
+ std::is_constructible<T, U&&>::value &&
+ std::is_assignable<T&, U&&>::value &&
+ (!std::is_scalar<T>::value ||
+ !std::is_same<typename std::decay<U>::type, T>::value),
+ optional<T>&>::type
+optional<T>::operator=(U&& v)
{
if (this->has_value()) {
this->value() = v;