3 ms·
> std::unique_ptr<Foo> doesn't have any overhead over Foo* in code where semantics is the same Not true. And you just refuted yourself by being up the ABI ques
by kccqzy 4y ago
> std::unique_ptr<Foo> doesn't have any overhead over Foo* in code where semantics is the same
Not true. And you just refuted yourself by being up the ABI question. You should watch Titus Winters' presentation on this topic where he compiles code using unique_ptr and raw pointers, compares the assembler produced, and explains why unique_ptr has non-zero overhead. The overhead is indeed coming from the ABI. Google has been wanting the next C++ to break ABI but they didn't get enough votes in the standard committee.
https://youtu.be/rHIkrotSwcc https://youtu.be/rHIkrotSwcc
- ncmncm 4y agoNot breaking binary compatibility is a pure good. The standard could pull unique_ptr in as a built-in feature with a different name, and retain backward compatibility at cost of an unfortunate redundancy. Code using unique_ptr would gradually transition to the new thing. Of course each would have a move constructor from the other, to ease the transition.