};
};
+
+struct CheckEqualityComparable: Sfinae
+{
+ static int &v;
+ template<typename T>
+ static Yes f(int (*)[sizeof(reinterpret_cast<const T &>(v)==reinterpret_cast<const T &>(v))]);
+ using Sfinae::f;
+};
+
+template<typename T>
+struct IsEqualityComparable: Sfinae::Evaluate<CheckEqualityComparable, T> { };
+
} // namespace Msp
#endif
virtual const std::type_info &type_id() const = 0;
virtual StoreBase *clone() const = 0;
+ virtual bool type_equals(const StoreBase &) const = 0;
+ virtual bool value_equals(const StoreBase &) const = 0;
};
template<typename T>
virtual const std::type_info &type_id() const { return typeid(T); }
virtual StoreBase *clone() const { return new Store<T>(data); }
+ virtual bool type_equals(const StoreBase &s) const { return dynamic_cast<const Store<T> *>(&s); }
+ virtual bool value_equals(const StoreBase &s) const { return value_equals_<T>(s); }
+
+ template<typename U>
+ typename EnableIf<IsEqualityComparable<U>::value, bool>::Yes value_equals_(const StoreBase &s) const
+ { const Store<T> *t = dynamic_cast<const Store<T> *>(&s); return (t && t->data==data); }
+
+ template<typename U>
+ typename EnableIf<IsEqualityComparable<U>::value, bool>::No value_equals_(const StoreBase &) const
+ { return false; }
};
StoreBase *store;
return dynamic_cast<Store<typename RemoveConst<T>::Type> *>(store)!=0;
}
+ bool check_same_type(const Variant &v) const
+ { return store && v.store && store->type_equals(*v.store); }
+
+ bool operator==(const Variant &v) const
+ { return store && v.store && store->value_equals(*v.store); }
+
+ bool operator!=(const Variant &v) const
+ { return !(operator==(v)); }
+
template<typename T>
operator T() const
{ return value<T>(); }