RVO + optional allows you do design differently Is there any proposals for non-nullable pointers ?

RVO + optional allows you do design differently
Is there any proposals for non-nullable pointers ? Would it even be practical ?
You already invited:

meilinda

Upvotes from:

The problem with pointers is that you can copy them without knowing about the ownership. If I can't set a pointer to null and always have to point to a valid object, that is just asking for trouble, someone somewhere *will* leave a dangle, or use some magic static-lifetime object to refer to "None" and such...
An either-type or error-type (`std::variant`, `std::optional`) is much more semantically viable, albeit it introduces a possible extra round of indirection, checking the invariant of a pointer "cannot be null" would result in the same amount of overhead.

If you wanna answer this question please Login or Register