Last Updated: June 6, 2026
std::any is a container that holds a single value of any type, where the type isn't known to the consumer at compile time and is recovered at runtime through std::any_cast. It is C++17's mechanism for storing a value of unknown type so a different piece of code can recover the type later. The header is <any>, the type lives in namespace std, and the entire chapter assumes C++17 or later. Compile examples with g++ -std=c++17.