File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55#pragma once
66
77#include " RTTR_Assert.h"
8+ #include < type_traits>
89
910// / Call a member function trough an object and a member function pointer
1011#define CALL_MEMBER_FN (object, ptrToMember ) ((object).*(ptrToMember))
@@ -24,17 +25,22 @@ inline T absDiff(T a, T b)
2425 return (a > b) ? a - b : b - a;
2526}
2627
27- // / Same as static_cast<T> but assert that it actually can be casted via dynamic_cast
28+ // / Same as static_cast<T> but assert the correct dynamic type (in debug mode)
29+ // / Use like: checkedCast<Derived*>(basePtr)
2830template <typename T, typename T_Src>
2931inline T checkedCast (T_Src* src)
3032{
33+ static_assert (std::is_pointer_v<T>, " T must be a pointer type" );
3134 RTTR_Assert (!src || dynamic_cast <T>(src));
3235 return static_cast <T>(src);
3336}
3437
38+ // / Same as static_cast<T&> but assert the correct dynamic type (in debug mode)
39+ // / Use like: checkedCast<Derived>(baseRef)
3540template <typename T, typename T_Src>
3641inline T& checkedCast (T_Src& src)
3742{
43+ static_assert (std::is_class_v<T>, " T must be a plain type" );
3844 RTTR_Assert (dynamic_cast <T*>(&src));
3945 return static_cast <T&>(src);
4046}
You can’t perform that action at this time.
0 commit comments