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

前端 未结 5 711
没有蜡笔的小新
没有蜡笔的小新 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:37

    Irrespective of anything that might be automatically done by the compiler I'd say that:

    • If any member has meaningful and beneficial move semantics, that the class should have this move semantics too. (-> std::vector members)
    • If any dynamic allocations are involved when copying, move operations make sense.

    Put otherwise, if move can do something more efficiently than copy, it makes sense to add it. In your really_trivial a move could only be as efficient as the copy already is.

提交回复
热议问题