Add known_cast to type casts

This commit is contained in:
Danny Robson 2012-06-20 16:48:40 +10:00
parent 8c5dd1eea1
commit 481f55a9c4

View File

@ -117,4 +117,21 @@ size_cast (const V v) {
return static_cast<T> (v); return static_cast<T> (v);
} }
//-----------------------------------------------------------------------------
template <typename T, typename V>
T*
known_cast (V *v) {
CHECK_HARD (nullptr != dynamic_cast<T> (v));
return static_cast<T> (v);
}
template <typename T, typename V>
T&
known_cast (V &v) {
CHECK_NOTHROW (dynamic_cast<T> (v));
return static_cast<T> (v);
}
#endif #endif