How to enforce copy elision, why it won't work with deleted copy constructor?

前端 未结 3 403
孤独总比滥情好
孤独总比滥情好 2020-12-01 17:58

I have an uncopiable class. Copying this would be problematic. I want to guarantee that it won\'t be ever copied, so I made its copy constructor deleted

3条回答
  •  暖寄归人
    2020-12-01 18:41

    Return value optimization (RVO and NRVO) does not mean the requirement that the types involved by copyable or movable is dropped. This requirement applies, whether you get RVO or not.

    The most likely reason this is so is that copy elision is not (currently) enforced. It is an optimization that may take place, and it would not make sense for code to compile or not based on whether that optimization is applied in a particular implementation.

    In C++17, RVO wil be enforced in some circumstances, and the requirements of copyability and movability will be dropped.

提交回复
热议问题