From b9a3f2e7e22e3757e863af102c20cc465e1cc02b Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Sun, 12 Jan 2020 17:26:12 +0100 Subject: STL Support: enhance behavior of cm::dynamic_reference_cast Ensure cm::dynamic_reference_cast has same behavior as dynamic_cast on reference: raise std::bad_cast if dynamic_cast is not possible. --- Utilities/std/cmext/memory | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Utilities/std/cmext/memory b/Utilities/std/cmext/memory index 540a3de..50e79df 100644 --- a/Utilities/std/cmext/memory +++ b/Utilities/std/cmext/memory @@ -6,6 +6,8 @@ #ifndef cmext_memory #define cmext_memory +#include + #include namespace cm { @@ -24,7 +26,13 @@ template = 0> T& dynamic_reference_cast(O& item) { - return *(dynamic_cast(item.get())); + auto p = dynamic_cast(item.get()); + + if (p == nullptr) { + throw std::bad_cast(); + } + + return *p; } } // namespace cm -- cgit v0.12