isocpp
isocpp copied to clipboard
observer_ptr
Upon reading your document, https://github.com/tvaneerd/isocpp/blob/master/observer_ptr.md, I found one missing argument which is the main reason I am looking into observer_ptr
, namely the technique called strong typing (see, e.g., the blogpost at https://www.fluentcpp.com/2016/12/05/named-constructors/). In my case, I have two variables with vastly different meaning (like double radius
and double diameter
in blogpost), but with the same pointer type (say double *radius_handle
and double *diameter_handle
for the sake of example, though you may come up with something better). To distinguish them (from a function overloading perspective) I plan on wrapping them in distinct class types as described in the blogpost (e.g., a class called RadiusHandle
to hold double* radius_handle
as member). Rather than just boxing/unboxing at every relevant function as the blogpost suggests, I had the idea to simply use observer_ptr
as the base class for my strong types, and just use those strong types directly as they are via the observer_ptr
functionality. No need to box and unbox. In fact, in this scenario, only owners needs to see the raw pointers (whose types can't be distinguished), and all observers can just use the strong types.
If you want, you can use this argument in favor of standardizing observer_ptr
. Otherwise, just close this documentation request.