• -0がないことで、ハッシュ値が⼀意に定まる • 異なる値-0と0を同じハッシュ値とする、のようなことがなくなる struct X { int a; char b; // strong_ordering(全順序)で順序が返る auto operator<=>(const X&) = default; }; auto ord = x <=> y; if (ord == 0) { … } struct X { int a; char b; }; X x = …; // 自動でハッシュ値を計算してくれる (将来) size_t hash = hash_as_bytes(x);
pop count (⽴っているビット数)、連続した0 or 1の数 float f = 3.14f; // memcpy()のconstexpr版のようなもの auto a = bit_cast<uint32_t>(f); // 2の累乗関係 auto b = bit_ceil(127u); // 128 auto c = bit_floor(129u); // 128 // 循環シフト auto i = static_cast<uint8_t>(0b0000'0001u); std::uint8_t a = rotr(i, 3); assert(a == 0b0010'0000u); // 立っているビット数 auto i = static_cast<uint8_t>(0b1000'1010u); int b = popcount(i); // 3