Why is `T(const T&&)` called a move constructor?

无人久伴 提交于 2019-12-05 08:04:19

Here are some of the differences between move constructors and other constructors:

  • Move constructors can be defaulted
  • Move constructors don't prevent a type from being a "literal type"
  • Non-trivial move constructors prevent a type from being a "trivially copyable type"
  • Move constructors prevent the implicit move constructor from being generated
  • Move constructors may be automatically called by standard library functions

As far as I can tell, for all of those, not calling X(const X &&) a move constructor gives undesirable results.

You give an alternative: it might be called a copy constructor instead. That too seems to have undesirable results: it would suppress the implicit copy constructor.

Whether a move constructor actually moves doesn't matter. A POD type may have a move constructor too. It'll just be making a copy, but it's still called a move constructor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!