Zero cost compared to a raw pointer. You are comparing apple and oranges if you compare it to a regular variable.
It has a null check on destructor (and a delete of course), which is good enough for "zero cost" to me
Hmm, now i thinked about this one but perhaps it is fair to compare unique_ptr to regular variables as well.
I guess it is more complicated than i thought, but i think it is fair to compare them pointers too. Because most of the time you will probably need to store it as a pointer
Re:C++20 has been approved
by tempsolution on Sunday September 06, 2020 @01:14PM
(#24392869)
What are you talking about? unique_ptr contains a pointer, that's it. Yes, to represent a pointer you have to contain a point. Passing it on or not makes zero difference and using a website that return unoptimized C++, is not a good place to gather intel. unique_ptr is zero cost, unless you use it across library boundaries without LTO.
If you pass a unique_ptr it has to have redirection through a pointer, so it isn't quite zero cost.
However, since the entire point of using a smart pointer is to control the ownership I'm not that bothered.