-
Notifications
You must be signed in to change notification settings - Fork 592
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
Add move ctor and assignment operator to InputStream #2092
Add move ctor and assignment operator to InputStream #2092
Conversation
I've merged my changes to your branch. The issue is that I can't move the stream into the lambda. The following doesn't work: [self, outAsync = outAsync->shared_from_this(), stream = std::move(is), requestId, dispatchCount]() mutable
{
if (self->sentAsync(outAsync.get()))
{
self->dispatchAll(stream, requestId, dispatchCount);
}
} The
Do you see a way to make this work? |
Did you try to move the function?
This seems to work, only tested with clang
|
I'll give it a try. |
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.
Looks good! I guess that we need to test that it's usable for our use cases. I agree this is preferable to the swap
calls.
I tried and it doesn't work. The capture of a lambda must be copyable, even if we never copy it. So either we somehow pass this InputStream as a parameter to the function (and the |
I works when you use a template parameter for passing the lambda, as in the example I posted. |
I believe this works because you don't use a |
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.
If it's not used anywhere, do we give up on this PR?
This PR updates ConnectionI to use it in one spot. I am in favor of merging this PR so it can be used more. |
I think it's good to have and we should use it where we can. |
This PR adds a move ctor and assignment operator to InputStream and uses them in a few spots.
Move ctor / move-assignment operator is more idiomatic than swap in modern C++. Unfortunately we rely on swap keeping "instance" as is which makes this PR not quite correct.