mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Added bad cast check.
This commit is contained in:
parent
3f639e37f0
commit
e6673afa0e
14
peglib.h
14
peglib.h
@ -84,7 +84,12 @@ public:
|
||||
>
|
||||
T& get() {
|
||||
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 <
|
||||
@ -101,7 +106,12 @@ public:
|
||||
>
|
||||
const T& get() const {
|
||||
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 <
|
||||
|
Loading…
Reference in New Issue
Block a user