From 91a52123d1c109f2de5ef6047b0d4c7a3fa25b96 Mon Sep 17 00:00:00 2001 From: Yuri Kovalenko Date: Sat, 15 Aug 2020 21:56:09 +0300 Subject: [PATCH 1/2] fixed some &&-qualified methods for optional case --- include/tl/optional.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/tl/optional.hpp b/include/tl/optional.hpp index ad8ae2f..cbe5dff 100644 --- a/include/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -1322,7 +1322,7 @@ class optional : private detail::optional_move_assign_base, static_assert(std::is_move_constructible::value && std::is_convertible::value, "T must be move constructible and convertible from U"); - return has_value() ? **this : static_cast(std::forward(u)); + return has_value() ? std::move(**this) : static_cast(std::forward(u)); } /// Destroys the stored value if one exists, making the optional empty @@ -1582,7 +1582,7 @@ template class optional { static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), **this) + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); } @@ -1601,7 +1601,7 @@ template class optional { static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), **this) + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); } #endif @@ -1624,7 +1624,7 @@ template class optional { static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), **this) + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); } @@ -1645,7 +1645,7 @@ template class optional { static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), **this) + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); } #endif @@ -2033,7 +2033,7 @@ template class optional { static_assert(std::is_move_constructible::value && std::is_convertible::value, "T must be move constructible and convertible from U"); - return has_value() ? **this : static_cast(std::forward(u)); + return has_value() ? std::move(**this) : static_cast(std::forward(u)); } /// Destroys the stored value if one exists, making the optional empty From d3d37ec927673e1b4a6d27cee77d263426c87b82 Mon Sep 17 00:00:00 2001 From: Yuri Kovalenko Date: Sat, 15 Aug 2020 23:37:43 +0300 Subject: [PATCH 2/2] fixed build --- include/tl/optional.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/include/tl/optional.hpp b/include/tl/optional.hpp index cbe5dff..2bb3279 100644 --- a/include/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -741,8 +741,7 @@ class optional : private detail::optional_move_assign_base, static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), **this) - : result(nullopt); + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); } template @@ -1582,7 +1581,7 @@ template class optional { static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), std::move(**this)) + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); } @@ -1601,7 +1600,7 @@ template class optional { static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), std::move(**this)) + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); } #endif @@ -1624,7 +1623,7 @@ template class optional { static_assert(detail::is_optional::value, "F must return an optional"); - return has_value() ? detail::invoke(std::forward(f), std::move(**this)) + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); } @@ -2033,7 +2032,7 @@ template class optional { static_assert(std::is_move_constructible::value && std::is_convertible::value, "T must be move constructible and convertible from U"); - return has_value() ? std::move(**this) : static_cast(std::forward(u)); + return has_value() ? **this : static_cast(std::forward(u)); } /// Destroys the stored value if one exists, making the optional empty