-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improve move semantics in Expected #4326
Improve move semantics in Expected #4326
Conversation
This patch unconditionally moves an `Unexpected<U>` value parameter as long as `U` is not a reference. If `U` is a reference the code should not compile. An error type that holds a reference is a strange use-case, and an overload is not provided. If it is required in the future it can be added. The `Expected(U r)` overload should take a forwarding ref.
I'm a little tempted to replace the |
I did add a patch to replace Edit: Ugh, I just noticed how our automatic formatting screws that up. We might have to update our clang-format before we start using concepts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for fixing my bugs!
typename = std::enable_if_t<std::is_convertible_v<U, T>>> | ||
constexpr Expected(U r) : Base(T{std::forward<U>(r)}) | ||
template <typename U> | ||
requires std::convertible_to<U, T> constexpr Expected(U && r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. We really need to tune up clang-format for requires
clauses. I think this would read way better as...
template <typename U>
requires std::convertible_to<U, T>
constexpr Expected(U&& r)
: Base(T{std::forward<U>(r)})
{
}
But we need to get a few test cases into the code base before we clean that up. Carry on...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because we use clang 10 for formatting. When I use clang 15 is formats in a reasonable way. I hope we can update our clang format shortly. I also don't mind delaying this patch until after we update formatting.
* Improve move semantics in Expected: This patch unconditionally moves an `Unexpected<U>` value parameter as long as `U` is not a reference. If `U` is a reference the code should not compile. An error type that holds a reference is a strange use-case, and an overload is not provided. If it is required in the future it can be added. The `Expected(U r)` overload should take a forwarding ref. * Replace enable_if with concepts in Expected
* Improve move semantics in Expected: This patch unconditionally moves an `Unexpected<U>` value parameter as long as `U` is not a reference. If `U` is a reference the code should not compile. An error type that holds a reference is a strange use-case, and an overload is not provided. If it is required in the future it can be added. The `Expected(U r)` overload should take a forwarding ref. * Replace enable_if with concepts in Expected
This patch unconditionally moves an
Unexpected<U>
value parameter as long asU
is not a reference. IfU
is a reference the code should not compile. An error type that holds a reference is a strange use-case, and an overload is not provided. If it is required in the future it can be added.The
Expected(U r)
overload should take a forwarding ref.