any主要作用:
1.可以用作判断当前值的是什么类型
2.any比void更加安全,而且更容易使用
struct Test
{
int a;
int b;
};
int main()
{
Test a;
a.a = 50;
a.b = 40;
std::any c = a;
if (c.type() == typeid(Test))
{
auto [f,s]= any_cast<Test>(a);
cout << f<<"and" << s << endl;
}
return 0;
}