vector<any> items;↵
items.push_back(42);↵
items.push_back(3.14);↵
items.push_back(string("hello"));↵
items.push_back(vector<int>{1, 2, 3});↵
↵
for (const auto& item : items) {↵
cout << "Type: " << item.type().name() << " -> ";↵
if (item.type() == typeid(int))↵
cout << any_cast<int>(item);↵
else if (item.type() == typeid(double))↵
cout << any_cast<double>(item);↵
else if (item.type() == typeid(string))↵
cout << any_cast<string>(item);↵
else↵
cout << "[complex type]";↵
cout << endl;↵
}↵
↵
cout << "Has value: " << items[0].has_value() << endl;