#include <any>
#include <iostream>
#include <string>
using namespace std;
class Test {
public:
Test() { cout << "Test()" << endl; }
Test(Test &&t) { cout << "Test(Test &&t)" << endl; }
Test(const Test &t) { cout << "Test(const Test &t)" << endl; }
~Test() { cout << "~Test()" << endl; }
void func() { cout << "func()" << endl; }
};
int main() {
any a = make_any<Test>();
cout << a.has_value() << endl;
cout << a.type().name() << endl;
cout << "------ 1" << endl;
any_cast<Test>(a).func();
cout << "------ 2" << endl;
cout << "------ 3" << endl;
any_cast<Test &>(a).func();
cout << "------ 4" << endl;
cout << "------ 5" << endl;
a = 1;
cout << "------ 6" << endl;
cout << a.type().name() << endl;
cout << any_cast<int>(a) << endl;
try {
cout << any_cast<string>(a) << endl;
} catch (bad_any_cast &e) {
cout << e.what() << endl;
}
cout << "------ 7" << endl;
cout << any_cast<int>(&a) << endl;
cout << *any_cast<int>(&a) << endl;
cout << any_cast<string>(&a) << endl;
cout << "------ 8" << endl;
a.reset();
return 0;
}