Let's say I have a simple class with a setter:
class MyClass
{
public:
void setName(std::string name)
{
_name = std::move(name);
}
private:
std::string _name;
};
I'm using std::move here, but if I were to omit this and just write _name = name, could the compiler implicitly move the name argument since it isn't used anywhere else in the setter? It can almost be treated as an rvalue in the assignment expression because it isn't being referenced by name anywhere else.
Can compilers do this? Do existing compilers do this?