const T &value() const { return const_cast<Variant *>(this)->get<T>(); }
template<typename T>
- bool check_type() const { return funcs==get_functions<typename std::remove_cv<T>::type>(); }
+ bool has_type() const { return type_equals(funcs, get_functions<typename std::remove_cv<T>::type>()); }
- bool check_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<typename T>
+ DEPRECATED bool check_type() const { return has_type<T>(); }
+
+ DEPRECATED bool check_same_type(const Variant &v) const { return has_same_type(v); }
bool operator==(const Variant &v) const { return (has_same_type(v) && funcs->compare(storage, v.storage)); }
bool operator!=(const Variant &v) const { return !(operator==(v)); }
operator T() const { return value<T>(); }
private:
+ static bool type_equals(const Functions *, const Functions *);
+
template<typename T>
static constexpr bool is_small() { return (sizeof(T)<=INTERNAL_SIZE && alignof(T)<=alignof(void *)); }
template<typename T>
-inline void Variant::assign(const T &value)
+inline void Variant::assign(const T &v)
{
if(funcs)
funcs->destroy(storage);
funcs = get_functions<typename std::remove_cv<T>::type>();
- create(storage, value);
+ create(storage, v);
}
inline void Variant::copy_from(const Variant &v)
return **reinterpret_cast<T **>(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<typename T>
inline const Variant::Functions *Variant::get_functions()
{