I know there is a question about std::any vs std::variant, but std::optional is also about a same thing. C++ std::variant vs std::any
I know there is a question about std::any vs std::variant, but std::optional is also about a same thing. C++ std::variant vs std::any
I have a very general rule:
Every time you want to use a union use std::variant.
Every time you want to use a void* use std::any.
Every time you want to return nullptr as an indication of an error use std::optional.