So I have this really ugly code:
template <typename T>
std::conditional_t<sizeof(T) == sizeof(char),
char,
conditional_t<sizeof(T) == sizeof(short),
short,
conditional_t<sizeof(T) == sizeof(long),
long,
enable_if_t<sizeof(T) == sizeof(long long),
long long>>>> foo(T bar){return reinterpret_cast<decltype(foo(bar))>(bar);}
I'm using nested conditional_t
s to make a case-statement of sorts. Is there something out there that accomplishes this more elegantly or do I need to cook up my own templatized-case-statement?
Note: I am actually aware that this use of reinterpret_cast
is bad: Why Doesn't reinterpret_cast Force copy_n for Casts between Same-Sized Types?