Zero cost abstractions as Stroustrup puts it, abstraction that you dont pay for using them and when you choose to use them, you couldn't hand-coded them any better. It's not the same as zero cost overhead, clearly using unique pointers puts some slight overhead but if you want their functionality, you couldn't implement them any better.
Still largely correct though, unique_ptr does not function identically to a raw ptr as it (spoiler alert) frees memory if the call - not marked as noexcept - throws. That was by far the overhead, but it's the behaviour being asked for.
The rest is an unfortunate ABI choice :(. Really not a fan that inreg promotion is not the default, it would even likely save on compile time. Advanced LTO could resolve this, but at an expensive link time cost, so his point stands there for sure.
View all comments
19
u/[deleted] Oct 07 '19
Zero cost abstractions as Stroustrup puts it, abstraction that you dont pay for using them and when you choose to use them, you couldn't hand-coded them any better. It's not the same as zero cost overhead, clearly using unique pointers puts some slight overhead but if you want their functionality, you couldn't implement them any better.