You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might be more about GSL than this project. It seems to me that offering a conversion from T to not_null looses the potential to detect certain bugs at compile-time.
if I have a function that returns a raw (potentially null) pointer, and I carelessly pass it to a function taking not_null it will compile fine, and will try report a bug at run-time when it is likely too late.
Instead, if the constructor from T were explicit, an inadvertent assignment:
use_ptr(make_ptr());
would be impossible, and I would be forced to explicitly require a potentially unsafe conversion:
use_ptr(not_null<T>{make_ptr()});
This would be a kind of the signature: by writing this cast, I am taking the responsibility for guaranteeing that the raw pointer will not be null. If it is not the case, you will know that I did it consciously.
The text was updated successfully, but these errors were encountered:
It might be more about GSL than this project. It seems to me that offering a conversion from
T
tonot_null
looses the potential to detect certain bugs at compile-time.if I have a function that returns a raw (potentially null) pointer, and I carelessly pass it to a function taking
not_null
it will compile fine, and will try report a bug at run-time when it is likely too late.Instead, if the constructor from
T
were explicit, an inadvertent assignment:would be impossible, and I would be forced to explicitly require a potentially unsafe conversion:
This would be a kind of the signature: by writing this cast, I am taking the responsibility for guaranteeing that the raw pointer will not be null. If it is not the case, you will know that I did it consciously.
The text was updated successfully, but these errors were encountered: