Hacker News new | ask | show | jobs
by temac 2197 days ago
> Value types in C++ cannot be null

They can just not exist. And C++ being C++, dereferencing an empty std::optional is UB. In practice this particular UB often leads to way worse consequences than more "conventional" null-pointer derefs.

1 comments

Then write your own optional that always checks on dereference or toggle whatever compilation flag enables checking in the standard library you are using.