The C++ standard library lacks a type to denote a smart pointer is not null. For raw pointer there is std::reference_wrapper, or a plain reference.
Other third-party libraries provide such a type, such as gsl::strict_not_null.
Fix all issues by adding util::NotNull<SmartPtrType>, an alias of gsl::strinct_not_null, which documents (and checks) that the inner pointer is never null.
This type can be used when passing never-null smart pointers between functions. It removes the need to Assert() the pointer before dereference. For example, in a getter function:
util::NotNull<std::unique_ptr<Stats>> GetStats()
{
return util::NotNull{std::make_unique<Stats>()};
}
int main()
{
auto stats{GetStats()};
stats->foo; // This can never lead to a nullptr deref
// Assert(stats)->foo; // This is redundant and won't compile
}