Alexey104
Alexey104

Reputation: 1281

Should I explicitly tell the compiler to move the string in this case?

void SomeClass::setName(std::string name)
{
    name_ = std::move(name);
}

Is this explicit std::move() redundant for the compiler?

Upvotes: 1

Views: 124

Answers (1)

eerorika
eerorika

Reputation: 238421

Is this explicit std::move() redundant for the compiler?

No. Without std::move() the operand would be an lvalue and thus you would be using the copy assignment operator.

Upvotes: 3

Related Questions