pointers - Enforce NULL checking in c++ -
my method can return kind of pointer ( example boost::shared_ptr ) , pointer may null. there way enforce users of code check, if empty or not ?
some example of such things - scals's option container, may boost has boost::option ?
you can following:
- return smart pointer type throws exception if accessed , set null.
- throw exception instead of returning null pointer
- return std::optional (or boost::optional) expresses intent (i.e. "value may missing") better pointer
Comments
Post a Comment