22 General utilities library [utilities] (original) (raw)

22.11 Bit manipulation [bit]

22.11.7 Counting [bit.count]

In the following descriptions, let N denote numeric_limits<T>​::​digits.

template<class T> constexpr int countl_zero(T x) noexcept;

Returns: The number of consecutive 0 bits in the value of x, starting from the most significant bit.

[Note 1:

Returns N if x == 0.

— _end note_]

template<class T> constexpr int countl_one(T x) noexcept;

Returns: The number of consecutive 1 bits in the value of x, starting from the most significant bit.

[Note 2:

Returns N if x == numeric_limits<T>​::​max().

— _end note_]

template<class T> constexpr int countr_zero(T x) noexcept;

Returns: The number of consecutive 0 bits in the value of x, starting from the least significant bit.

[Note 3:

Returns N if x == 0.

— _end note_]

template<class T> constexpr int countr_one(T x) noexcept;

Returns: The number of consecutive 1 bits in the value of x, starting from the least significant bit.

[Note 4:

Returns N if x == numeric_limits<T>​::​max().

— _end note_]

template<class T> constexpr int popcount(T x) noexcept;

Returns: The number of 1 bits in the value of x.