1

A move constructor of class T is a non-template constructor whose first parameter is T&&, const T&&, volatile T&&, or const volatile T&&, and either there are no other parameters, or the rest of the parameters all have default values.

Source: https://en.cppreference.com/w/cpp/language/move_constructor

So const T&& is actually a thing. But doesn't the const defeat the purpose of &&? What are the practical uses for const T&&?

Yashas
  • 1,154
  • 1
  • 12
  • 34
  • In addition to the linked answer you *can* actually define a meaningful move constructor for a class using a `const&&` parameter if the move operation is a no-op (as it is for e.g. `int`). – Konrad Rudolph Jul 17 '20 at 10:57
  • @KonradRudolph But in that case copying and moving is the same. If all class members are primitives like int there is no point in implementing move semantics at all. – Eric Jul 17 '20 at 12:26
  • @Eric That’s true. I was thinking that there might be a situation where the presence of a move constructor would change semantics based on testing via `std::is_move_constructible` but obviously this shouldn’t make a difference. – Konrad Rudolph Jul 17 '20 at 12:30

0 Answers0