What optimization does move semantics provide if we already have RVO?

前端 未结 8 1869
北海茫月
北海茫月 2020-12-04 17:50

As far as I understand one of the purposes of adding move semantics is to optimize code by calling special constructor for copying \"temporary\" objects. For example, in th

8条回答
  •  感动是毒
    2020-12-04 18:30

    Your posted example only takes const lvalue references and so explicitly cannot have move semantics applied to it, as there is not a single rvalue reference in there. How can move semantics make your code faster when you implemented a type without rvalue references?

    In addition, your code is already covered by RVO and NRVO. Move semantics apply to far, far more situations than those two do.

提交回复
热议问题