diff --git a/lib/castable.h b/lib/castable.h index e398a72755..fa9d27ef36 100644 --- a/lib/castable.h +++ b/lib/castable.h @@ -57,6 +57,14 @@ class ICastable { BUG_CHECK(result, "Cast failed: %1% is not a %2%", this, typeid(T).name()); return result; } + + /// Performs a checked cast. A BUG occurs if the cast fails. + template + T *checkedTo() { + auto *result = to(); + BUG_CHECK(result, "Cast failed: %1% is not a %2%", this, typeid(T).name()); + return result; + } }; #endif /* LIB_CASTABLE_H_ */