If we want to represent an optional value, we can use std::unique_ptr (C++11) and heap allocation (nullptr denoting absence). However, this incurs a runtime cost and can fail (and throw).
std::optional (C++17) will not allocate dynamic memory and only incurs the cost of storing a boolean.
Compiler Explorer link: https://compiler-explorer.com/z/sqf9ro1cE