35 #ifndef NEKTAR_LIB_UTILITIES_CHECKEDCAST_H
36 #define NEKTAR_LIB_UTILITIES_CHECKEDCAST_H
40 #include <type_traits>
44 namespace LibUtilities
50 class =
typename std::enable_if
52 std::is_floating_point<typename std::remove_reference<Ti>::type>::value
53 && std::is_integral <typename std::remove_reference<To>::type>::value
58 Ti min = std::numeric_limits<To>::min();
59 Ti max = std::numeric_limits<To>::max();
60 ASSERTL0(param >= min,
"Casting would narrow (underflow).");
61 ASSERTL0(param <= max,
"Casting would narrow (overflow).");
62 return static_cast<To
>(param);
#define ASSERTL0(condition, msg)
To checked_cast(const Ti param)
checked cast from float types only to int types
The above copyright notice and this permission notice shall be included.