35 #ifndef NEKTAR_LIB_UTILITIES_CHECKEDCAST_H
36 #define NEKTAR_LIB_UTILITIES_CHECKEDCAST_H
40 #include <type_traits>
44 namespace LibUtilities
47 template <
class To,
class Ti,
48 class =
typename std::enable_if<
49 std::is_floating_point<
50 typename std::remove_reference<Ti>::type>::value &&
52 typename std::remove_reference<To>::type>::value>::type>
55 Ti min = std::numeric_limits<To>::min();
56 Ti max = std::numeric_limits<To>::max();
57 ASSERTL0(param >= min,
"Casting would narrow (underflow).");
58 ASSERTL0(param <= max,
"Casting would narrow (overflow).");
59 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.