Skip to content

Remove complicated syntax in argument_loader::call() #2044

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

Closed

Conversation

rhaschke
Copy link
Contributor

There doesn't seem to be the need for std::move(*this).

@wjakob wjakob requested a review from jagerman December 30, 2019 15:37
@wjakob
Copy link
Member

wjakob commented Dec 30, 2019

  • @jagerman, who designed this this implementation.

@jagerman
Copy link
Member

jagerman commented Dec 30, 2019

The reason for the rvalue qualification on the methods is that call_impl moves away the argument casters, which is not a good thing to do if the caller context isn't itself an rvalue, and so I think those should stay. The std::move(*this).template elimination seems okay: call_impl isn't actually rvalue qualified and is private, so the move there seems not actually needed.

@rhaschke
Copy link
Contributor Author

Actually, the caller context isn't an rvalue as call_impl isn't declared as an rvalue method.
Do I miss something?

@jagerman
Copy link
Member

Actually, the caller context isn't an rvalue as call_impl isn't declared as an rvalue method.
Do I miss something?

I'm talking about the caller of call(). You're right that the std::move for the call_impl invocation doesn't need the move.

@rhaschke
Copy link
Contributor Author

rhaschke commented Dec 31, 2019

I think I am confused because call() has the rvalue qualifiers, while call_impl() has not.
I would expect both to have the same qualifiers.
I agree that having them nicely indicates that the internal argcasters are moved away.
On the other hand, removing them (everywhere) greatly simplifies the syntax.

There doesn't seem to be the need for std::move(*this).
@rhaschke rhaschke force-pushed the simplify-argument-loader-call branch from 1286ba3 to 5deb072 Compare January 2, 2020 08:10
@jagerman
Copy link
Member

jagerman commented Jan 3, 2020

I think you misunderstood me; I probably wasn't sufficiently clear:

  • leave the && qualifications on call() so that it can't be called in non-rvalue context (because it moves away internal members)
  • simplify away the std::move() on the internal call to call_impl because it isn't needed: it's a private, internal implementation method (yes, it moves away members, but it's private so it seems fine to not requiring that it also be &&-qualified, and just remove the unneeded std::move(...) where it is invoked).

@rhaschke
Copy link
Contributor Author

rhaschke commented Jan 3, 2020

I deliberately removed all &&-qualifiers to illustrate that they are not required.
I'm still convinced that you should use a consistent approach of using &&-qualifiers everywhere or never.

@jagerman
Copy link
Member

jagerman commented Jan 4, 2020

I deliberately removed all &&-qualifiers to illustrate that they are not required.

They are not required for compilation, but they serve a significant purpose on the public method: they signal that this method leaves the object in an undefined state (with the internal data moved away), and prevent it from being called in an lvalue context where that would be inappropriate. There currently is no such call, of course, and that's the point: such a call would intentionally fail to compile, but if you remove the && qualifier it won't fail to compile, and that to me is a bug.

@jagerman
Copy link
Member

jagerman commented Jan 4, 2020

(If you want to go the other way and add && to the internal private method, that's fine and arguably more correct)

@rhaschke
Copy link
Contributor Author

rhaschke commented Jan 5, 2020

If you want to go the other way and add && to the internal private method, that's fine and arguably more correct

That's fine with me too. Hence, I filed a new PR #2057 and will close this one here.

@rhaschke rhaschke closed this Jan 5, 2020
@rhaschke rhaschke deleted the simplify-argument-loader-call branch January 5, 2020 09:25
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.

3 participants