32 #ifndef PLANCK_SAFE_CAST_H 33 #define PLANCK_SAFE_CAST_H 38 template<
typename T1,
typename T2,
bool s1,
bool s2>
struct safe_cast_helper__
41 template<
typename T1,
typename T2>
struct safe_cast_helper__ <T1,T2,true,true>
43 static T1 cast (
const T2 &arg)
46 planck_assert(T2(res)==arg,
"safe_cast: value changed during cast");
51 template<
typename T1,
typename T2>
struct safe_cast_helper__ <T1,T2,false,false>
53 static T1 cast (
const T2 &arg)
56 planck_assert(T2(res)==arg,
"safe_cast: value changed during cast");
61 template<
typename T1,
typename T2>
struct safe_cast_helper__ <T1,T2,true,false>
63 static T1 cast (
const T2 &arg)
67 "safe_cast: value changed during cast");
72 template<
typename T1,
typename T2>
struct safe_cast_helper__ <T1,T2,false,true>
74 static T1 cast (
const T2 &arg)
78 "safe_cast: value changed during cast");
86 template<
typename T1,
typename T2>
inline T1
safe_cast(
const T2 &arg)
88 return safe_cast_helper__<T1,T2,std::numeric_limits<T1>::is_signed,
89 std::numeric_limits<T2>::is_signed>::cast(arg);
T1 safe_cast(const T2 &arg)
#define planck_assert(testval, msg)