diff --git a/cast.hpp b/cast.hpp index 03de1419..3ecd03ae 100644 --- a/cast.hpp +++ b/cast.hpp @@ -144,35 +144,6 @@ namespace cruft::cast { } - /////////////////////////////////////////////////////////////////////////// - /// Assert if the value is not a pointer to a subclass of T, else return - /// the converted value. Note: this is only a debug-time check and is - /// compiled out in optimised builds. - template < - concepts::pointer T, - typename V - > - T - known (V *const v) - { - CHECK (dynamic_cast (v)); - return static_cast (v); - } - - - //------------------------------------------------------------------------- - template < - concepts::reference T, - typename V - > - T - known (V &v) - { - CHECK_NOTHROW (dynamic_cast (v)); - return reinterpret_cast (v); - } - - /////////////////////////////////////////////////////////////////////////// /// Cast a pointer from one type to another, asserting that the required /// alignment of the destination type has been satisfied. @@ -196,6 +167,38 @@ namespace cruft::cast { } + /////////////////////////////////////////////////////////////////////////// + /// Assert if the value is not a pointer to a subclass of T, else return + /// the converted value. Note: this is only a debug-time check and is + /// compiled out in optimised builds. + template < + concepts::pointer T, + typename V + > + T + known (V *const v) + { + if constexpr (std::is_class_v) { + CHECK (dynamic_cast (v)); + } + + return alignment (v); + } + + + //------------------------------------------------------------------------- + template < + concepts::reference T, + typename V + > + T + known (V &v) + { + CHECK_NOTHROW (dynamic_cast (v)); + return reinterpret_cast (v); + } + + /////////////////////////////////////////////////////////////////////////// /// Cast from SrcT to DstT and damn any consequences; just make it compile. template