Difference between std :: is_signed <T> and std :: numeric_limits <T> :: is_signed?

Both std::is_signed<T>and std::numeric_limits<T>::is_signedmust give answers signature T.
Why are there two indicators for signing (i.e. C C ++ 11)?

+5
source share
1 answer

I'm going to fear that the only difference is that it is std::numeric_limits<T>specialized for the user type. Such a custom type could, of course, provide its own value for is_signed. But a request std::is_signed<T>::valuefor this type will always return falseif it has std::is_signed<T>not been specially specialized.

The condition std::is_signed<T>seems to represent

is_arithmetic<T>::value && T(-1) < T(0)

: Howard Hinnant , , std::numeric_limits<> , <type_traits> , , is_signed .

, std::numeric_limits<T>::is_signed true ( ), std::is_signed<T>::value false .

+7

All Articles