From: Mikko Rasa Date: Mon, 2 Jan 2023 21:38:27 +0000 (+0200) Subject: Fallback to comparing typeid in Variant if funcs are not the same X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5d51c374869f13f762039f58c03f3c5d75c12f07;p=libs%2Fcore.git Fallback to comparing typeid in Variant if funcs are not the same On Windows it looks like instantiations of a function template in different modules may have different addresses of its static locals. --- diff --git a/source/core/variant.h b/source/core/variant.h index 60501f3..5de5a72 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -61,9 +61,9 @@ public: const T &value() const { return const_cast(this)->get(); } template - bool has_type() const { return funcs==get_functions::type>(); } + bool has_type() const { return type_equals(funcs, get_functions::type>()); } - bool has_same_type(const Variant &v) const { return (funcs && funcs==v.funcs); } + bool has_same_type(const Variant &v) const { return type_equals(funcs, v.funcs); } template DEPRECATED bool check_type() const { return has_type(); } @@ -77,6 +77,8 @@ public: operator T() const { return value(); } private: + static bool type_equals(const Functions *, const Functions *); + template static constexpr bool is_small() { return (sizeof(T)<=INTERNAL_SIZE && alignof(T)<=alignof(void *)); } @@ -162,6 +164,16 @@ inline T &Variant::get() return **reinterpret_cast(storage); } +inline bool Variant::type_equals(const Functions *funcs1, const Functions *funcs2) +{ + if(!funcs1 || !funcs2) + return false; + else if(funcs1==funcs2) + return true; + else + return funcs1->get_type()==funcs2->get_type(); +} + template inline const Variant::Functions *Variant::get_functions() {