AlgoMaster Logo

std::any (C++17)

Last Updated: June 6, 2026

Low Priority
36 min read

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.

Premium Content

Subscribe to unlock full access to this content and more premium articles.