X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fvariant.h;h=338ec90865d5a8dc0dc269e96f73577b1c42c04c;hb=d15b96b498d7cad51a0cb1dd949f70a04af246e9;hp=1ad086e70381254422d92330e277b7fd43f4826d;hpb=99b9121e2158603372c7313400283b622e6754d8;p=libs%2Fcore.git diff --git a/source/core/variant.h b/source/core/variant.h index 1ad086e..338ec90 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -39,24 +39,24 @@ private: virtual const std::type_info &type_id() const { return typeid(T); } virtual StoreBase *clone() const { return new Store(data); } virtual bool type_equals(const StoreBase &s) const { return dynamic_cast *>(&s); } - virtual bool value_equals(const StoreBase &s) const { return value_equals_(s); } + virtual bool value_equals(const StoreBase &s) const { return _value_equals(s); } template - typename std::enable_if::value, bool>::type value_equals_(const StoreBase &s) const + typename std::enable_if::value, bool>::type _value_equals(const StoreBase &s) const { const Store *t = dynamic_cast *>(&s); return (t && t->data==data); } template - typename std::enable_if::value, bool>::type value_equals_(const StoreBase &) const + typename std::enable_if::value, bool>::type _value_equals(const StoreBase &) const { return false; } }; - StoreBase *store = 0; + StoreBase *store = nullptr; public: Variant() = default; template Variant(const T &v): store(new Store::type>(v)) { } - Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } + Variant(const Variant &v): store(v.store ? v.store->clone() : nullptr) { } ~Variant() { delete store; } template @@ -69,8 +69,11 @@ public: Variant &operator=(const Variant &v) { + if(&v==this) + return *this; + delete store; - store = (v.store ? v.store->clone() : 0); + store = (v.store ? v.store->clone() : nullptr); return *this; } @@ -101,7 +104,7 @@ public: template bool check_type() const { - return dynamic_cast::type> *>(store)!=0; + return dynamic_cast::type> *>(store); } bool check_same_type(const Variant &v) const