Skip to content

Commit 1d93a02

Browse files
committed
optional<T>::transform() const &&: move the value into the function
If *this is an rvalue reference, we're required to move the value contained into the function passed to transform(). Do that.
1 parent cf05829 commit 1d93a02

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/beman/optional/optional.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ constexpr auto optional<T>::transform(F&& f) const&& {
818818
static_assert(!std::is_same_v<U, in_place_t>);
819819
static_assert(!std::is_same_v<U, nullopt_t>);
820820
static_assert(std::is_object_v<U> || std::is_reference_v<U>); /// References now allowed
821-
return (has_value()) ? optional<U>{std::invoke(std::forward<F>(f), value_)} : optional<U>{};
821+
return (has_value()) ? optional<U>{std::invoke(std::forward<F>(f), std::move(value_))} : optional<U>{};
822822
}
823823

824824
/// Calls `f` if the optional is empty

0 commit comments

Comments
 (0)