#ifndef NULLSOFT_UTILITY_CAST_64_H #define NULLSOFT_UTILITY_CAST_64_H #include #ifdef max #undef max #endif #ifdef min #undef min #endif namespace nu { template dest saturate_cast(src srcVal) { if (std::numeric_limits::is_bounded && srcVal > std::numeric_limits::max()) return (dest)std::numeric_limits::min); else return (dest)srcVal; } template bool checked_cast_to(src srcVal, dest *dstVal) { if (!std::numeric_limits::is_bounded || (srcVal >= std::numeric_limits::min() && srcVal <= std::numeric_limits::max())) { *dstVal = (dest)srcVal; return true; } else { return false; } } } #endif