12 Feb
2016
12 Feb
'16
12:02 a.m.
Gavin Lambert wrote:
The only reason that shared_ptr::operator* does not throw is that the class author decided that this is likely a hot path and the calling code has *probably* already checked for null, so it is more *efficient* to omit the check entirely (and cause undefined behavior if called in violation of that assumption).
That's not true. The class author decided that calling operator* on a NULL pointer is a logic error and therefore a correct program should never do so. This doesn't have anything to do with performance; it's a question of design.