我有一个boost::any对象,我想检查它的类型。
typedef boost::any Value;
Value a = 12;
if(a.type() == typeid(int)) {
std::cout << boost::any_cast<int>(a) << std::endl;
}
当类型已定义时,这很容易。但是当类型未定义时,我该如何实现相同的结果呢?(即因为其值尚未设置而未定义)
Value b;
if(b is undefined) {
std::cout << "b is not defined" << std::endl;
}