Skip to content
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

[util.smartptr.atomic.general] Remove redundant explicit construction of return types #6077

Merged
merged 3 commits into from Mar 12, 2023

Conversation

hewillk
Copy link
Contributor

@hewillk hewillk commented Feb 10, 2023

No description provided.

@@ -4833,7 +4833,7 @@
while (p && p->t != t)
p = p->next;

return shared_ptr<node>(move(p));
return shared_ptr<node>(std::move(p));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we explicitly converting a shared_ptr<node> to shared_ptr<node> in the first place? What's wrong with return p;?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return p; is a more reasonable approach. (I'd be happy if it could be changed to this)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, let's go ahead and change it. We like to show a variety of styles in examples, but writing something long and complicated when something short and simple will do isn't style, it's obfuscation.

@hewillk hewillk changed the title [util.smartptr.atomic.general] Add std:: qualified for move in example [util.smartptr.atomic.general] Remove redundant explicit construction of return types Feb 10, 2023
Copy link
Member

@jensmaurer jensmaurer left a comment

Choose a reason for hiding this comment

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

Looks good.

@tkoeppe, please squash when merging.

Copy link
Member

@jwakely jwakely left a comment

Choose a reason for hiding this comment

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

You now need to look outside that member function to see what its return type is, because it uses auto for the return type and auto for the declaration of p, and now this removes the only mention of the type. While it's not hard to look at the declaration of head, is this actually making the example clearer?
We could change the return type from auto to shared_ptr<node> maybe.

@tkoeppe tkoeppe merged commit 5a974f7 into cplusplus:main Mar 12, 2023
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.

None yet

5 participants