A simple template alias will do:
#include <type_traits> template<typename T> struct identity { using type = T; }; template<typename T> using try_make_signed = typename std::conditional< std::is_integral<T>::value, std::make_signed<T>, identity<T> >::type;
And here is how to check it:
int main() { static_assert(::is_same< try_make_signed<unsigned int>::type, int >::value, "!"); static_assert(std::is_same< try_make_signed<double>::type, double >::value, "!"); }
Here is a living example .
source share