Why would I std::move an std::shared_ptr?

前端 未结 6 1921
一整个雨季
一整个雨季 2021-01-29 19:14

I have been looking through the Clang source code and I found this snippet:

void CompilerInstance::setInvocation(
    std::shared_ptr          


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 20:00

    Copying a shared_ptr involves copying its internal state object pointer and changing the reference count. Moving it only involves swapping pointers to the internal reference counter, and the owned object, so it's faster.

提交回复
热议问题