diff --git a/types/casts.hpp b/types/casts.hpp index 7c443ea4..fe408bd3 100644 --- a/types/casts.hpp +++ b/types/casts.hpp @@ -26,6 +26,7 @@ #include +//----------------------------------------------------------------------------- namespace detail { template T @@ -58,6 +59,7 @@ sign_cast (const V v) { return detail::_sign_cast(v); } +//----------------------------------------------------------------------------- namespace detail { // Same sign, no possibility of truncation with larger target type template @@ -84,4 +86,15 @@ T trunc_cast (V v) { return detail::_trunc_cast (v); } + +//----------------------------------------------------------------------------- +template +T +size_cast (const V v) { + CHECK_HARD (std::numeric_limits::min () <= v); + CHECK_HARD (std::numeric_limits::max () >= v); + + return static_cast (v); +} + #endif