From be67e7f4a28332bfab44d0cbc9f008e24ddf3510 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 27 Sep 2012 23:38:10 +0300 Subject: [PATCH] Don't give out a non-const reference from a const Variant --- source/core/variant.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 -- 2.43.0