cast: add sanity cast

This commit is contained in:
Danny Robson 2018-12-03 15:29:04 +11:00
parent 9ea44a5063
commit d6b80da18b

View File

@ -184,4 +184,17 @@ namespace cruft::cast {
return reinterpret_cast<DstT> (src);
#pragma GCC diagnostic pop
}
///////////////////////////////////////////////////////////////////////////
/// Cast from SrcT to DstT, performing sanity checks on the src and dst
/// values before returning the result.
template <typename DstT, typename SrcT>
DstT sanity (SrcT src)
{
cruft::debug::sanity (src);
DstT dst = static_cast<DstT> (src);
cruft::debug::sanity (dst);
return dst;
}
}