From: Mikko Rasa Date: Thu, 27 Sep 2012 20:38:10 +0000 (+0300) Subject: Don't give out a non-const reference from a const Variant X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=be67e7f4a28332bfab44d0cbc9f008e24ddf3510 Don't give out a non-const reference from a const Variant --- diff --git a/source/core/variant.h b/source/core/variant.h index e00885c..4a0c89c 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -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