X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fvariant.h;h=515350de6ae5543158e20b6e2c20d4ef786163fb;hp=e00885c94210ef720c3d48c42769d99a7d3182f8;hb=c3e242c2629cbc9645258b30aaf07b7285d4372b;hpb=c7afef88380ebebc8c2b04e48664d73281ec8848 diff --git a/source/core/variant.h b/source/core/variant.h index e00885c..515350d 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -31,7 +31,7 @@ private: { T data; - Store(T d): data(d) { } + 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); } @@ -61,14 +61,28 @@ public: return *this; } +private: template - T &value() const + Store::Type> *get_typed_store() const { typedef typename RemoveConst::Type NCT; Store *s = dynamic_cast *>(store); if(!s) throw type_mismatch(typeid(T), (store ? store->type_id() : typeid(void))); - return s->data; + return s; + } + +public: + template + T &value() + { + return get_typed_store()->data; + } + + template + const T &value() const + { + return get_typed_store()->data; } template