M
M
Mercury132018-07-25 13:15:19
C++ / C#
Mercury13, 2018-07-25 13:15:19

Is Object(std::wstring&&) required in terms of optimization?

We have such a code.

class Object
{
public:
  Object() = default;
  Object(std::wstring x) : value(std::move(x)) {}    // интересный механизм, предложенный статическим анализатором clang
  Object(std::wstring&& x) : value(std::move(x)) {}     // НУЖНО ЛИ?
private:
  std::wstring value;
};

Do we need a third constructor in terms of optimization? Or without it, the system will understand that a temporary object can be gutted with std:: move?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
terrier, 2018-07-25
@Mercury13

No, not needed. The second constructor covers both cases -
- rvalue comes - do one move ( no copy )
- lvalue comes - do copy + move

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question