X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fvariant.h;h=1ad086e70381254422d92330e277b7fd43f4826d;hb=9b38e20254913629a0db40e8eb8e1c42e1728e41;hp=2dd9732fc60dd4faf1a692eef1be63d9c83328cd;hpb=90fc7638aee23270fe005f86dd1b492d67015c13;p=libs%2Fcore.git diff --git a/source/core/variant.h b/source/core/variant.h index 2dd9732..1ad086e 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -2,6 +2,7 @@ #define MSP_CORE_VARIANT_H_ #include +#include #include #include "meta.h" @@ -11,7 +12,7 @@ class type_mismatch: public std::runtime_error { public: type_mismatch(const std::type_info &, const std::type_info &); - ~type_mismatch() throw() { } + virtual ~type_mismatch() throw() = default; }; @@ -41,20 +42,20 @@ private: virtual bool value_equals(const StoreBase &s) const { return value_equals_(s); } template - typename EnableIf::value, bool>::Yes value_equals_(const StoreBase &s) const + typename std::enable_if::value, bool>::type value_equals_(const StoreBase &s) const { const Store *t = dynamic_cast *>(&s); return (t && t->data==data); } template - typename EnableIf::value, bool>::No value_equals_(const StoreBase &) const + typename std::enable_if::value, bool>::type value_equals_(const StoreBase &) const { return false; } }; - StoreBase *store; + StoreBase *store = 0; public: - Variant(): store(0) { } + Variant() = default; template - Variant(const T &v): store(new Store::Type>(v)) { } + Variant(const T &v): store(new Store::type>(v)) { } Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } ~Variant() { delete store; } @@ -62,7 +63,7 @@ public: Variant &operator=(const T &v) { delete store; - store = new Store::Type>(v); + store = new Store::type>(v); return *this; } @@ -75,9 +76,9 @@ public: private: template - Store::Type> *get_typed_store() const + Store::type> *get_typed_store() const { - typedef typename RemoveConst::Type NCT; + typedef typename std::remove_cv::type NCT; Store *s = dynamic_cast *>(store); if(!s) throw type_mismatch(typeid(T), (store ? store->type_id() : typeid(void))); @@ -100,7 +101,7 @@ public: template bool check_type() const { - return dynamic_cast::Type> *>(store)!=0; + return dynamic_cast::type> *>(store)!=0; } bool check_same_type(const Variant &v) const