When will adding a move constructor and a move assignment operator really start make a difference?

前端 未结 5 753
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 21:11

Considering the high quality of today\'s compilers regarding return value optimization (both RVO and NRVO), I was wondering at what class complexity it\'s actually meaningfu

5条回答
  •  被撕碎了的回忆
    2021-01-05 21:43

    Typically, moving makes sense when the class holds some kind of resource, where a copy would involve copying that resource and moving would not. The easiest example is dynamically allocated memory. However, it is worth noting that the compiler will automatically generate move constructors and operators, just like it will for copying.

提交回复
热议问题