It is an undefine behavior for using invalid iterator. Instead, we can replace it with std::optional.