// Bad
MyType x{42, "hello"};
foo(x);
// Good
foo({42,"hellow"});
std::string str{"hello"};
std::vector<std::string> coll;
coll.push_back(str);
coll.push_back(std::move(str));
std::string line;
while(std::getline(myStream, line)) {
coll.push_back(std::move(line));
}
std::move() std::string foo(){
std::string name;
...
// BAD:
return std::move(name);
}
See Name Returned Value Optimization for more details.
std::move() whereby either NRVO or move semantics will perform:
std::string foo(){
std::string name;
...
return name;
}