Re:Why introduce `std::launder` rather than have the compile...
by gpderetta on Saturday January 22, 2022 @09:58AM
(#30037206)
Shared_ptr and unique_ptr are not replacement for raw C pointers. And the reason they are not blessed with language syntax is because user can and often do implement their own, so those two library types are not particularly special.
[ Parent
| on HN ]
Re:Why introduce `std::launder` rather than have the compile...
by BenFrantzDale on Saturday January 22, 2022 @10:18AM
(#30037397)
Agreed. And a huge strength of C++ is that you can write low-level classes like these and have them be fully performant and have reasonable native-feeling syntax. Almost no other languages provide that.
Re:Why introduce `std::launder` rather than have the compile...
by IiydAbITMvJkqKf on Saturday January 22, 2022 @11:53AM
(#30038321)
Specifically, both shared_ptr and unique_ptr are owning pointers. Using plain old pointers for non-owning variables is idiomatic.
Re:Why introduce `std::launder` rather than have the compile...
by tialaramex on Saturday January 22, 2022 @02:28PM
(#30039990)
Non-owning pointers are a genuinely useful tool, but as a tool they're more welding torch than hammer, if that's what you needed it's really what you needed - but most often it probably isn't what you needed at all and will cause more harm than good.
So it's strange to provide them with stuff like terse built-in syntax, while not providing anything similar for the thing people will want all the time, ownership. Result: The Right Thing™ is harder to do and wastes visual space compared to the Wrong Thing. A "correct" program ends up full of boilerplate just to get what you'd obviously want.