From: Mikko Rasa Date: Mon, 15 Dec 2008 11:40:24 +0000 (+0000) Subject: Add copy constructor and copy assignment to Variant X-Git-Tag: 1.1~7 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7db1e6d50594b47a32ecca5a349a4e8540f890c0;p=libs%2Fcore.git Add copy constructor and copy assignment to Variant --- 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 {