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

Take an rvalue reference parameter when the intention is to take ownership #1174

Open
eggrobin opened this issue Dec 21, 2016 · 1 comment
Open
Assignees

Comments

@eggrobin
Copy link
Member

To prevent accidental copy of large objects:
e.g.

void Phagocytize(std::vector<T>&& v);

rather than

void Phagocytize(std::vector<T> v);

so that

Phagocitize(some_vector);

is illegal.

@eggrobin
Copy link
Member Author

More specifically, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rf-consume.

We don't need to do this for move-only objects.
Importantly, we must take care that a parameter like that actually gets moved:

Flag all X&& parameters (where X is not a template type parameter name) where the function body uses them without std::move.

Sorry, something went wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant