Have you read the Motivation section of proposal N4282 that you contacted?
Often, it often took a programmer a lot of time and time to check the code to distinguish between the use that any particular null pointer is bound to, even if that use has no control role at all. As Loyk A. Joli noted, βitβs not easy to eliminate the foggy T * pointer that only observes the data ... Even if it just serves for documentation, I will have a certain sense of having a distinguished type.β Our experience allows us to agree with this assessment.
In other words, this makes the code more self-documenting.
For example, if I see the following function:
void do_something(Foo *foo);
then I donβt know if do_something accepts ownership of foo, whether Foo wants an array of indefinite length, just needs a reference to NULL, uses it as a Google C ++ Style Guide , or outdated C style code that just wants a link.
However, if I see
void do_something(observer_ptr<Foo> foo);
then I know that he is watching an instance of Foo and no more.
The basic C ++ recommendations contain several additional examples ( owner , not_null , etc.) of using templates, not to add functionality at runtime, but to better document the behavior.
source share