Add size_cast for size reductions
This commit is contained in:
parent
58e69fbd44
commit
93275a43a7
@ -26,6 +26,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
T
|
T
|
||||||
@ -58,6 +59,7 @@ sign_cast (const V v)
|
|||||||
{ return detail::_sign_cast<T,V>(v); }
|
{ return detail::_sign_cast<T,V>(v); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
namespace detail {
|
namespace detail {
|
||||||
// Same sign, no possibility of truncation with larger target type
|
// Same sign, no possibility of truncation with larger target type
|
||||||
template <typename T, typename V>
|
template <typename T, typename V>
|
||||||
@ -84,4 +86,15 @@ T
|
|||||||
trunc_cast (V v)
|
trunc_cast (V v)
|
||||||
{ return detail::_trunc_cast<T, V> (v); }
|
{ return detail::_trunc_cast<T, V> (v); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
template <typename T, typename V>
|
||||||
|
T
|
||||||
|
size_cast (const V v) {
|
||||||
|
CHECK_HARD (std::numeric_limits<T>::min () <= v);
|
||||||
|
CHECK_HARD (std::numeric_limits<T>::max () >= v);
|
||||||
|
|
||||||
|
return static_cast<T> (v);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user