| 209 | // Returns the the least significant bit from |value|. |
| 210 | template <typename T> |
| 211 | constexpr T LSB(T value) { |
| 212 | static_assert(std::is_integral<T>::value, "LSB requires integer type"); |
| 213 | if constexpr (std::is_unsigned_v<T>) { |
| 214 | // Prevent warnings about doing a -x on unsigned values. |
| 215 | return value & (~value + 1); |
| 216 | } else { |
| 217 | return value & -value; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | static_assert(LSB<uint32_t>(UINT32_MAX) == uint32_t(0x00000001), "LSB failed"); |
| 222 | static_assert(LSB<uint32_t>(0x10001000) == uint32_t(0x00001000), "LSB failed"); |
no outgoing calls
no test coverage detected