C++ 23 · Containers and algorithms
Hold one of several types
A type-safe union, visited with std::visit.
std::variant<int, std::string> value = "hello";
std::visit([](const auto& x) { std::cout << x << '\n'; }, value);
C++ 23 · Containers and algorithms
A type-safe union, visited with std::visit.
std::variant<int, std::string> value = "hello";
std::visit([](const auto& x) { std::cout << x << '\n'; }, value);
Was this page helpful?