isocpp / isocpp/CppCoreGuidelines
F15, in & retain copy, why not X?
@hsutter is already working on this.
Since Apr 3, 2017.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I'm not sure if this is the right forum to ask, and sorry if this has been asked before..
For parameter passing, when called function want to retain a copy, and the parameter is cheap to move, wouldn't be "X" is the simplest solution, and then inside the function move out from that? That gets rid of the need for two functions or templated version, and still leaves the opportunity to retain a copy for the caller too.
For example:
class Foo
{
std::vector<int> mThings;
public:
void SetThings(std::vector<int> Things)
{
mThings=std::move(Things);
}
};
And this way the caller still has option to retain copy:
Foo MyFoo;
MyFoo.SetThings(std::move(MyThings));
or if it does not want to retain a copy, it can use move:
MyFoo.SetThings(MyThings);
As I understand the code on the caller side would be the same with the current recommendation; but I think the called side is simpler.
What is it that I am missing?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.