]> git.tdb.fi Git - libs/core.git/commitdiff
Don't give out a non-const reference from a const Variant
authorMikko Rasa <tdb@tdb.fi>
Thu, 27 Sep 2012 20:38:10 +0000 (23:38 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 27 Sep 2012 20:38:10 +0000 (23:38 +0300)
source/core/variant.h

index e00885c94210ef720c3d48c42769d99a7d3182f8..4a0c89cf1a9a4b22661d28e62ba192a06004aabd 100644 (file)
@@ -61,14 +61,28 @@ public:
                return *this;
        }
 
+private:
        template<typename T>
-       T &value() const
+       Store<typename RemoveConst<T>::Type> *get_typed_store() const
        {
                typedef typename RemoveConst<T>::Type NCT;
                Store<NCT> *s = dynamic_cast<Store<NCT> *>(store);
                if(!s)
                        throw type_mismatch(typeid(T), (store ? store->type_id() : typeid(void)));
-               return s->data;
+               return s;
+       }
+
+public:
+       template<typename T>
+       T &value()
+       {
+               return get_typed_store<T>()->data;
+       }
+
+       template<typename T>
+       const T &value() const
+       {
+               return get_typed_store<T>()->data;
        }
 
        template<typename T>