fixed some &&-qualified methods for optional<MoveOnly> case

This commit is contained in:
Yuri Kovalenko
2020-08-15 21:56:09 +03:00
parent 0dfc7b4e41
commit 91a52123d1

View File

@ -1322,7 +1322,7 @@ public:
static_assert(std::is_move_constructible<T>::value &&
std::is_convertible<U &&, T>::value,
"T must be move constructible and convertible from U");
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
return has_value() ? std::move(**this) : static_cast<T>(std::forward<U>(u));
}
/// Destroys the stored value if one exists, making the optional empty
@ -1582,7 +1582,7 @@ public:
static_assert(detail::is_optional<result>::value,
"F must return an optional");
return has_value() ? detail::invoke(std::forward<F>(f), **this)
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
: result(nullopt);
}
@ -1601,7 +1601,7 @@ public:
static_assert(detail::is_optional<result>::value,
"F must return an optional");
return has_value() ? detail::invoke(std::forward<F>(f), **this)
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
: result(nullopt);
}
#endif
@ -1624,7 +1624,7 @@ public:
static_assert(detail::is_optional<result>::value,
"F must return an optional");
return has_value() ? detail::invoke(std::forward<F>(f), **this)
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
: result(nullopt);
}
@ -1645,7 +1645,7 @@ public:
static_assert(detail::is_optional<result>::value,
"F must return an optional");
return has_value() ? detail::invoke(std::forward<F>(f), **this)
return has_value() ? detail::invoke(std::forward<F>(f), std::move(**this))
: result(nullopt);
}
#endif
@ -2033,7 +2033,7 @@ public:
static_assert(std::is_move_constructible<T>::value &&
std::is_convertible<U &&, T>::value,
"T must be move constructible and convertible from U");
return has_value() ? **this : static_cast<T>(std::forward<U>(u));
return has_value() ? std::move(**this) : static_cast<T>(std::forward<U>(u));
}
/// Destroys the stored value if one exists, making the optional empty