X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fcore%2Fvariant.h;h=af204f2233f3c7759665a0f6b729bd52459d4326;hb=991fabc1956b73a4007859058fb44171000b452e;hp=5109dbcc11811ac8297f71e3903a1eb8c4f36f36;hpb=641a71730a0135fe647f6a230e9704d8b677f2c5;p=libs%2Fcore.git diff --git a/source/core/variant.h b/source/core/variant.h index 5109dbc..af204f2 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -12,7 +12,7 @@ class type_mismatch: public std::runtime_error { public: type_mismatch(const std::type_info &, const std::type_info &); - ~type_mismatch() throw() { } + ~type_mismatch() throw() override = default; }; @@ -36,27 +36,27 @@ private: Store(const T &d): data(d) { } - 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); } + const std::type_info &type_id() const override { return typeid(T); } + StoreBase *clone() const override { return new Store(data); } + bool type_equals(const StoreBase &s) const override { return dynamic_cast *>(&s); } + bool value_equals(const StoreBase &s) const override { 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; + StoreBase *store = nullptr; public: - Variant(): store(0) { } + 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