cast: add sanity cast
This commit is contained in:
parent
9ea44a5063
commit
d6b80da18b
13
cast.hpp
13
cast.hpp
@ -184,4 +184,17 @@ namespace cruft::cast {
|
|||||||
return reinterpret_cast<DstT> (src);
|
return reinterpret_cast<DstT> (src);
|
||||||
#pragma GCC diagnostic pop
|
#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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user