为什么要对 <bit> return 有符号数进行运算?
Why do operation on <bit> return signed numbers?
像
这样的操作
template< class T >
constexpr int popcount( T x ) noexcept;
return一个有符号整数,但是设置的位数永远不能为负数?选择有符号而不是无符号类型的动机是什么?
来自the paper:
The counting operations return "int" quantities, consistent with the rule "use an int unless you need something else". This choice does not reflect, in the type, the fact that counts are always non-negative.
gcc 的内部函数在这里 (__builtin_popcount
) 也 returns int
.
像
这样的操作template< class T >
constexpr int popcount( T x ) noexcept;
return一个有符号整数,但是设置的位数永远不能为负数?选择有符号而不是无符号类型的动机是什么?
来自the paper:
The counting operations return "int" quantities, consistent with the rule "use an int unless you need something else". This choice does not reflect, in the type, the fact that counts are always non-negative.
gcc 的内部函数在这里 (__builtin_popcount
) 也 returns int
.