std::is_unsigned 是否意味着 std::is_integral

Does std::is_unsigned imply std::is_integral

如果我需要满足 std::is_unsignedstd::is_integral 的类型,我是必须检查两者还是只检查 std::is_unsigned

cppreference 有此行 is_unsigned (https://en.cppreference.com/w/cpp/types/is_unsigned):

this results in true for the unsigned integer types and the type bool and in false for the signed integer types and the floating-point types. For any other type, value is false.

所以如果 is_unsignedtrue,那么 is_integral 也是如此。

是的,根据 cppreference

请记住,这并非在任何地方都有效,并且只保证对本机类型有效。我在 boost::multiprecision 给出错误的整数结果时遇到了问题。最好的方法是使用 numeric_limits:

std::numeric_limits<MyIntType>::is_signed