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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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