std::any测试
#include <any>
class A {
public:
int8_t a;
};
int main(int argc, char* argv[]) {
std::any num((int8_t)42);
auto a = std::any_cast<A>(num);
return 0;
}
异常: 0x00007FFA9385CD29 处(位于 test.exe 中)有未经处理的异常: Microsoft C++ 异常: std::bad_any_cast,位于内存位置 0x000000882B96FC50 处。
SafeAny测试
#include "SafeAny/safe_any.hpp"
class A {
public:
int8_t a;
};
int main(int argc, char* argv[]) {
Any num( (int8_t) 42 );
auto a = num.cast<A>();
}
异常:D:\SafeCppAny\test.cpp:12: Failure: due to unexpected exception with message: [Any::convert]: no known safe conversion between __int64 and class A
优点
SafeAny比std::any增加了错误位置,错误类型转换说明,方便问题定位
参考
GitHub - facontidavide/SafeCppAny: Extension of std::any with small object optmization and safe numeric conversion.
创作不易,小小的支持一下吧!






![[OPEN SQL] SELECT语句](https://i-blog.csdnimg.cn/direct/65634126c0b14030934dfc72c4721dd1.png)
![[数据结构]动态顺序表的实现与应用](https://i-blog.csdnimg.cn/direct/f5c016efacaa400b8762ad82e844ebfc.png)












