I was reading this post.
And I reached to the following code.
I was wondering:
Is
std::move
useful for strings (assuming the string is long enough)?Does it invalidate the previous string?
Where should I use it and where I should not?
.
class Name
{
public:
Name(std::string firstName, std::string lastName)
: firstName_(std::move(firstName))
, lastName_(std::move(lastName)) {}
void print() const
{
std::cout << lastName_ << ", " << firstName_ << '\n';
}
private:
std::string firstName_;
std::string lastName_;
};
My technique was always using
constructor(const std::string& argument): field(argument)