133 lines
3.5 KiB
Markdown
133 lines
3.5 KiB
Markdown
[bit.count]
|
||
|
||
# 22 General utilities library [[utilities]](./#utilities)
|
||
|
||
## 22.11 Bit manipulation [[bit]](bit#count)
|
||
|
||
### 22.11.7 Counting [bit.count]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15920)
|
||
|
||
In the following descriptions,
|
||
let N denote numeric_limits<T>::digits[.](#1.sentence-1)
|
||
|
||
[ð](#itemdecl:1)
|
||
|
||
`template<class T>
|
||
constexpr int countl_zero(T x) noexcept;
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15931)
|
||
|
||
*Constraints*: T is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#2.sentence-1)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15935)
|
||
|
||
*Returns*: The number of consecutive 0 bits in the value of x,
|
||
starting from the most significant bit[.](#3.sentence-1)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
Returns N if x == 0[.](#3.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#itemdecl:2)
|
||
|
||
`template<class T>
|
||
constexpr int countl_one(T x) noexcept;
|
||
`
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15951)
|
||
|
||
*Constraints*: T is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#4.sentence-1)
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15955)
|
||
|
||
*Returns*: The number of consecutive 1 bits in the value of x,
|
||
starting from the most significant bit[.](#5.sentence-1)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
Returns N if x == numeric_limits<T>::max()[.](#5.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#itemdecl:3)
|
||
|
||
`template<class T>
|
||
constexpr int countr_zero(T x) noexcept;
|
||
`
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15971)
|
||
|
||
*Constraints*: T is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#6.sentence-1)
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15975)
|
||
|
||
*Returns*: The number of consecutive 0 bits in the value of x,
|
||
starting from the least significant bit[.](#7.sentence-1)
|
||
|
||
[*Note [3](#note-3)*:
|
||
|
||
Returns N if x == 0[.](#7.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#itemdecl:4)
|
||
|
||
`template<class T>
|
||
constexpr int countr_one(T x) noexcept;
|
||
`
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15991)
|
||
|
||
*Constraints*: T is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#8.sentence-1)
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L15995)
|
||
|
||
*Returns*: The number of consecutive 1 bits in the value of x,
|
||
starting from the least significant bit[.](#9.sentence-1)
|
||
|
||
[*Note [4](#note-4)*:
|
||
|
||
Returns N if x == numeric_limits<T>::max()[.](#9.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#itemdecl:5)
|
||
|
||
`template<class T>
|
||
constexpr int popcount(T x) noexcept;
|
||
`
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L16011)
|
||
|
||
*Constraints*: T is an unsigned integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#10.sentence-1)
|
||
|
||
[11](#11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L16015)
|
||
|
||
*Returns*: The number of 1 bits in the value of x[.](#11.sentence-1)
|