Added bad cast check.

This commit is contained in:
yhirose 2015-02-14 10:20:19 -05:00
parent 3f639e37f0
commit e6673afa0e

View File

@ -84,7 +84,12 @@ public:
> >
T& get() { T& get() {
assert(content_); assert(content_);
return dynamic_cast<holder<T>*>(content_)->value_; auto p = dynamic_cast<holder<T>*>(content_);
assert(p);
if (!p) {
throw std::bad_cast();
}
return p->value_;
} }
template < template <
@ -101,7 +106,12 @@ public:
> >
const T& get() const { const T& get() const {
assert(content_); assert(content_);
return dynamic_cast<holder<T>*>(content_)->value_; auto p = dynamic_cast<holder<T>*>(content_);
assert(p);
if (!p) {
throw std::bad_cast();
}
return p->value_;
} }
template < template <