#include #include #include #include class Student { pubic: string name ; int id ; }; int main() { // 1. A vector of any can hold single elements of ANY type dynamically. // A tuple cannot do this because a tuple has a fixed, strict compile-time type schema. vector dynamic_registry ; dynamic_registry.push_back(42); // Stores an int dynamic_registry.push_back(string("Hello C++")); // Stores a string dynamic_registry.push_back(3.14159); // Stores a double dynamic_registry.push_back(Student{"Alice", 101}); // Stores a custom struct cout << "--- Processing Dynamic Types via any ---\n"; // 2. We inspect and extract the types at runtime for (const auto& item : dynamic_registry) { if (item.type() == typeid(int)) { // Extract using any_cast int value = any_cast(item); cout << "Found an integer: " << value << "\n"; } else if (item.type() == typeid(string)) { const auto& value = any_cast(item); cout << "Found a string: " << value << "\n"; } else if (item.type() == typeid(double)) { double value = any_cast(item); cout << "Found a double: " << value << "\n"; } else if (item.type() == typeid(Student)) { const auto& Student = any_cast(item); cout << "Found a custom Student struct: [Name: " << Student.name << ", ID: " << Student.id << "]\n"; } else { cout << "Unknown type found.\n"; } } return 0; }