Files
SH-Quizzes/ACMOJ-2090.cpp
2023-12-23 22:23:48 +08:00

22 lines
496 B
C++

#include "2090.hpp"
#include <iostream>
signed main() {
sjtu::any_ptr a = sjtu::make_any_ptr(int(1));
sjtu::any_ptr b = a;
a.unwrap<int>() = 2;
std::cerr << b.unwrap<int>() << std::endl; // 2
b = new std::string;
b.unwrap<std::string>() = "Hello, world!";
std::cerr << b.unwrap<std::string>() << std::endl; // Hello, world!
try {
a.unwrap<std::string>() = "a";
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl; // bad cast
}
return 0;
}