未验证 提交 faacbd27 编写于 作者: 石晓伟 提交者: GitHub

replace variant with any in variable.h, test=develop (#4000)

上级 c8de0f58
......@@ -33,19 +33,19 @@ class Variable {
template <typename T>
T* GetMutable() {
if (!blob_.is<T>()) blob_.set<T>();
if (!blob_.valid()) {
blob_.set<T>();
}
return blob_.get_mutable<T>();
}
template <typename T>
bool IsType() {
return blob_.type() == typeid(T).hash_code();
return blob_.is_type<T>();
}
private:
// variant<int, float, std::string, lite::Tensor> blob_;
variant<int, float, std::string, lite::Tensor, std::vector<lite::Tensor>>
blob_;
Any blob_;
};
} // namespace lite
......
......@@ -62,6 +62,9 @@ class Any {
template <typename T, typename... Args>
inline void construct(Args&&... args);
template <typename T>
inline bool is_type() const;
private:
template <typename T>
class TypeOnHeap;
......@@ -214,6 +217,14 @@ inline const std::type_info& Any::type() const {
}
}
template <typename T>
inline bool Any::is_type() const {
if ((type_ == nullptr) || (*(type_->ptype_info) != typeid(T))) {
return false;
}
return true;
}
template <typename T>
inline void Any::check_type() const {
CHECK_EQ((type_ == nullptr), false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册