Init
This commit is contained in:
22
ACMOJ-2090.cpp
Normal file
22
ACMOJ-2090.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user