Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some &&-qualified methods for optional<MoveOnly> case #42

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions include/tl/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,7 @@ class optional : private detail::optional_move_assign_base<T>,
static_assert(detail::is_optional<result>::value,
"F must return an optional");

return has_value() ? detail::invoke(std::forward<F>(f), **this)
: result(nullopt);
return has_value() ? detail::invoke(std::forward<F>(f), **this) : result(nullopt);
}

template <class F>
Expand Down Expand Up @@ -1322,7 +1321,7 @@ class optional : private detail::optional_move_assign_base<T>,
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
Expand Down Expand Up @@ -1645,7 +1644,7 @@ template <class T> class optional<T &> {
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
Expand Down