R
Rudi Cilibrasi
Hi everybody,
I have been studying the great new features of C++11, and realized
that we now have three main smart pointer types that are recommended:
unique_ptr, shared_ptr, and weak_ptr. I then noticed that so-called
raw pointers are not actually useless despite all the smart pointer
options now available. For instance, "non-owning raw pointers" are
the most efficient choice in cases where we know that another object
is managing the pointer lifetime for us and we are just acting as
observers.
http://herbsutter.com/elements-of-modern-c-style/
My problem with the use of old-style raw pointer syntax is that it is
not orthogonal when compared to the other three recommended template
pointer types. It makes use of the overloaded * operator that can be
used for multiply. It seems to me that the same argument against
using 0 for nullptr can be applied to using * for raw pointers. Why
don't we add a simple template wrapper to represent raw pointers that
is called "fast_ptr" in order to provide an easy-to-read documentary
syntax for raw pointers that avoids explicit use of the *. We can
still support unary * for people that prefer it, but being able to
completely avoid the use of unary * seems like it would make the
syntax easier to read, understand, and maintain. Then it becomes
possible to do things like grep for all _ptr types in a program
following this discipline, and the choice of which pointer type is
appropriate becomes more explicit in each case.
I look forward to reading your feedback on this matter. Best regards,
Rudi Cilibrasi
I have been studying the great new features of C++11, and realized
that we now have three main smart pointer types that are recommended:
unique_ptr, shared_ptr, and weak_ptr. I then noticed that so-called
raw pointers are not actually useless despite all the smart pointer
options now available. For instance, "non-owning raw pointers" are
the most efficient choice in cases where we know that another object
is managing the pointer lifetime for us and we are just acting as
observers.
http://herbsutter.com/elements-of-modern-c-style/
My problem with the use of old-style raw pointer syntax is that it is
not orthogonal when compared to the other three recommended template
pointer types. It makes use of the overloaded * operator that can be
used for multiply. It seems to me that the same argument against
using 0 for nullptr can be applied to using * for raw pointers. Why
don't we add a simple template wrapper to represent raw pointers that
is called "fast_ptr" in order to provide an easy-to-read documentary
syntax for raw pointers that avoids explicit use of the *. We can
still support unary * for people that prefer it, but being able to
completely avoid the use of unary * seems like it would make the
syntax easier to read, understand, and maintain. Then it becomes
possible to do things like grep for all _ptr types in a program
following this discipline, and the choice of which pointer type is
appropriate becomes more explicit in each case.
I look forward to reading your feedback on this matter. Best regards,
Rudi Cilibrasi