X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fvariant.h;h=6632831e9efa4557f777f36e03f30d416a853d0b;hp=6425fbfcbf7e4046d58105b445563f5e4d221acd;hb=7db1e6d50594b47a32ecca5a349a4e8540f890c0;hpb=3fd9d04e84cdd72aabe8f9878f9e8ff006275bb6 diff --git a/source/core/variant.h b/source/core/variant.h index 6425fbf..6632831 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -19,6 +19,7 @@ private: struct StoreBase { virtual ~StoreBase() { } + virtual StoreBase *clone() const =0; }; template @@ -27,6 +28,7 @@ private: T data; Store(T d): data(d) { } + virtual StoreBase *clone() const { return new Store(data); } }; StoreBase *store; @@ -35,6 +37,7 @@ public: Variant(): store(0) { } template Variant(const T &v): store(new Store::Type>(v)) { } + Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } ~Variant() { delete store; } template @@ -45,6 +48,13 @@ public: return *this; } + Variant &operator=(const Variant &v) + { + delete store; + store=(v.store ? v.store->clone() : 0); + return *this; + } + template T &value() const {