From 966af01d16a546c6bf803de6667a51976f9f1049 Mon Sep 17 00:00:00 2001 From: fruffy Date: Tue, 7 Nov 2023 16:39:01 -0500 Subject: [PATCH] Allow non-cast checkedTo cast. --- lib/castable.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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_ */