3 This file is part of libmspcore
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_CORE_VARIANT_H_
9 #define MSP_CORE_VARIANT_H_
21 virtual ~StoreBase() { }
25 struct Store: public StoreBase
29 Store(T d): data(d) { }
35 Variant(): store(0) { }
37 Variant(const T &v): store(new Store<typename RemoveConst<T>::Type>(v)) { }
38 ~Variant() { delete store; }
41 Variant &operator=(const T &v)
44 store=new Store<typename RemoveConst<T>::Type>(v);
51 typedef typename RemoveConst<T>::Type NCT;
52 Store<NCT> *s=dynamic_cast<Store<NCT> *>(store);
54 throw InvalidState("Type mismatch");
59 bool check_type() const
61 return dynamic_cast<Store<typename RemoveConst<T>::Type> *>(store)!=0;
66 { return value<T>(); }