Run-time check of integral conversion
The best I can imagine, in a simple way, is check if T(u) == u
and the signs of u
and T(u)
are the same
I mean something as
template <typename T, typename U>
bool IsRepresentable (U const & u)
{ return (T(u) == u) && (T(u) > T(0)) == (u > U(0)); }