Skip to content

Fixes to futures#505

Merged
sean-parent merged 5 commits intostlab:mainfrom
sean-parent:sean-parent/future-fixes
Nov 8, 2022
Merged

Fixes to futures#505
sean-parent merged 5 commits intostlab:mainfrom
sean-parent:sean-parent/future-fixes

Conversation

@sean-parent
Copy link
Member

@sean-parent sean-parent commented Oct 22, 2022

Fixed unnecessary copies of copyable result types when futures are used as rvalues. Propagating exceptions for move-only types are now scheduled on the executor (I'm not sure why they were not scheduled before). Added copy() algorithm to utility.hpp to explicitly copy objects. Added docs and tests.

Fixed unnecessary copies of copyable result types when futures are used as rvalues.
Propagating exceptions for move-only types are now scheduled on the executor (I'm not sure why they were not scheduled before).
Added `copy()` algorithm to utility.hpp to explicitly copy objects.
/// Returns a copy of the argument. Used to pass an lvalue to function taking an rvalue or to
/// copy a type with an `explicit` copy-constructor.
template <typename T>
T copy(const T& a) {
Copy link
Member

@fosterbrereton fosterbrereton Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously you gave an implementation of copy to be:

template <typename T>
constexpr std::decay_t<T> copy(T&& value) noexcept(
    noexcept(std::decay_t<T>{static_cast<T&&>(value)})) {
  static_assert(!std::is_same<std::decay_t<T>, T>::value, "explicit copy of rvalue.");
  return std::decay_t<T>{static_cast<T&&>(value)};
}

What's changed between now and then that's resulted in the greatly simplified variant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to use the above - nothing changed other than my memory of writing the above...

Copy link
Member

@fosterbrereton fosterbrereton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had one question about your copy implementation. Other than that I don't see anything wrong with this PR.

@sean-parent sean-parent merged commit d722622 into stlab:main Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants