Suppose in the below function:
template<typename T, typename U>
bool IsRepresentable(U u);
that T
and U
are non-bool integral types.
If the integer value of u
is representable in T
then IsRepresentable
should return true
, otherwise it should return false
.
What's the best way to implement IsRepresentable
in C++17? (or is there an exisiting similar function in the standard library?)
(My current thinking was a constexpr if-else chain around std::is_signed
/ sizeof
/ std::numeric_limits
- but am I missing some easier or more straightforward way?)