Nullable type in C++

std::optional is a type wrapper which wraps that type and an optional flag which says about the nullability of that type.

Sometimes we create an object which contains no valid data. We often a associate a flag or a special value, which decides the validity of the data. For example,

  • a pointer with value nullptr is a pointer that points to no location.