From faacbd27389a3e7cfe9eb50ec64a83c2144e0c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=99=93=E4=BC=9F?= <39303645+Shixiaowei02@users.noreply.github.com> Date: Wed, 29 Jul 2020 20:35:42 +0800 Subject: [PATCH] replace variant with any in variable.h, test=develop (#4000) --- lite/core/variable.h | 10 +++++----- lite/utils/any.h | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lite/core/variable.h b/lite/core/variable.h index 2c1e737a93..91d979f592 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 f658e4e658..f597ba600d 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); -- GitLab