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);

Official C++ 23 documentation

More containers and algorithms commands

All containers and algorithms commands · C++ 23 cheatsheet

Was this page helpful?