This commit is contained in:
2023-12-23 22:23:48 +08:00
commit 43ced8bd2a
58 changed files with 5702 additions and 0 deletions

32
ACMOJ-2096.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
#include "ACMOJ-2096.hpp"
#include <iostream>
signed main() {
using koishi::any;
any x;
x = 1919810;
std::cout << x.cast <int> () << std::endl;
x = 114.514;
try {
std::cout << x.cast <int> () << std::endl;
} catch (const std::exception &e) {
std::cout << e.what() << std::endl;
}
auto ptr = x.try_cast <double> ();
if (ptr) std::cout << "Double value: " << *ptr << std::endl;
// if C++ 17 or later, try this:
// if (auto ptr = x.try_cast <double> ()) std::cout << "Double value: " << *ptr << std::endl;
any y {x};
std::cout << y.cast <double> () << std::endl;
any z {std::move(x)};
if (x.is_empty()) std::cout << "x is empty" << std::endl;
std::cout << z.cast <double> () << std::endl;
return 0;
}