From d6b80da18b9177052cd8e1b380b674541e95e628 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 3 Dec 2018 15:29:04 +1100 Subject: [PATCH] cast: add sanity cast --- cast.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cast.hpp b/cast.hpp index 2ecf291c..86ead4c2 100644 --- a/cast.hpp +++ b/cast.hpp @@ -184,4 +184,17 @@ namespace cruft::cast { return reinterpret_cast (src); #pragma GCC diagnostic pop } + + + /////////////////////////////////////////////////////////////////////////// + /// Cast from SrcT to DstT, performing sanity checks on the src and dst + /// values before returning the result. + template + DstT sanity (SrcT src) + { + cruft::debug::sanity (src); + DstT dst = static_cast (src); + cruft::debug::sanity (dst); + return dst; + } }