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

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

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