【发布时间】:2020-01-03 14:33:42
【问题描述】:
我有一个 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;
}
【问题讨论】:
-
std::any 有 has_value() 方法,我希望 boost 也有。
标签: c++ boost types null boost-any