multiple data types in one variable

For example, std::variant<std::string, int> var;means that var is either std::string or int. Not both.

  • It is similar to union but different. You can view std::variant it as a typesafe union
  • Not permitted to hold references, arrays, or void type
  • You can’t have an empty variant