diff --git a/lite/core/variable.h b/lite/core/variable.h index 2c1e737a9370118f33dac2e1c51400ae04b4b0f1..91d979f592f43e74cf99f24b978c9d18322b8cf9 100644 --- a/lite/core/variable.h +++ b/lite/core/variable.h @@ -33,19 +33,19 @@ class Variable { template T* GetMutable() { - if (!blob_.is()) blob_.set(); + if (!blob_.valid()) { + blob_.set(); + } return blob_.get_mutable(); } template bool IsType() { - return blob_.type() == typeid(T).hash_code(); + return blob_.is_type(); } private: - // variant blob_; - variant> - blob_; + Any blob_; }; } // namespace lite diff --git a/lite/utils/any.h b/lite/utils/any.h index f658e4e6583507a97c7db29d71b9ac676c5e7d7f..f597ba600dbe529f4a78ae0b28a0f476d47f93e7 100644 --- a/lite/utils/any.h +++ b/lite/utils/any.h @@ -62,6 +62,9 @@ class Any { template inline void construct(Args&&... args); + template + inline bool is_type() const; + private: template class TypeOnHeap; @@ -214,6 +217,14 @@ inline const std::type_info& Any::type() const { } } +template +inline bool Any::is_type() const { + if ((type_ == nullptr) || (*(type_->ptype_info) != typeid(T))) { + return false; + } + return true; +} + template inline void Any::check_type() const { CHECK_EQ((type_ == nullptr), false);