Modified ref-qualifiers return type for Optional::value() and Optional::operator*
Summary: Optional::value() returns a temporary object when the object is an rvalue. This is different in semantics then what boost::optional/std::optional do. The decision to make the copy or not should be up to the user and not the library. Consider an example: ``` void F(Optional<T> &&opt) { T&& t = std::move(opt).get(); // I know `opt` is alive in this scope, I should be able to keep a rvalue ref to the internals } // if we were to return a `T`, that would actually return a new temporary. ``` ``` void G(T&& t); G(std::move(opt).get()); // This could have surprising behavior too ! ``` This change modified the return type to be `T&&` and also introduces an extra overload for `const T&&`. Also, deleted two test-cases that assume the lifetime to be extended. This is a breaking change but this brings folly::Optional on parity with other siblings. Closes https://github.com/facebook/folly/pull/353 Reviewed By: ddrcoder Differential Revision: D3714962 Pulled By: yfeldblum fbshipit-source-id: 1794d51590062db4ad02fc8688cb28a06712c076
Showing
Please register or sign in to comment