Join GitHub today
Using `not_null` with *smart pointers*. #225
I think this issue really needs to be brought up here first: Microsoft/GSL#89
I made a comment on that issue over at
According to the guidelines for passing smart pointers it seems that the only reason we should be passing a smart pointer to a function is when that fuction modifies the ownership in some way. Otherwise, the recommendation is that we pass a raw pointer.
Bearing that in mind I am not sure that
After all a function receiving a
Maybe there are use-cases I have missed but it seems to me the main use for the
Therefore we might not want a
To that effect we could create
A use case where we may want to use the class with smart pointer is passing a shared resource while creating an object.
@galik "Therefore we might not want a not_null to contain a smart pointer, only its associated raw pointer"
I see two use-cases:
rodiers has given two nice examples of where a function might want to accept or return a smart pointer (it is a factory, or a sink). In those cases, using not_null around a smart pointer would be entirely appropriate, it does not interfere with the fact that a smart pointer is still being passed/returned to express lifetime semantics.
So I think both guidelines are fine as-is: the guideline to only use smart pointers as parameters to express lifetime semantics and the recommendation to use not_null to indicate a particular property of a pointer - raw or smart.
The issue over at the GSL repo seems to be more about the specific characteristics of that implementation of not_null...which is a discussion best had over there.