📅  最后修改于: 2020-12-15 04:29:38             🧑  作者: Mango
位集表示固定大小的N位序列,并存储0或1的值。0表示值为false或未设置位,而1表示值为true或设置了位。 Bitset类模拟布尔值的空间高效数组,其中每个元素仅占用一位。
当它模拟数组时,其索引也从第0个位置开始。可以使用下标运算符访问位集中的单个位。例如,要访问位集foo的第一个元素,请使用foo [0] 。
Bitset类为构造函数提供了从整数以及从字符串。位集的大小在编译时是固定的。 STL提供了vector
以下是
template class bitset;
N-比特集的大小。
成员函数可以将以下成员类型用作参数或返回类型。
Sr.No. | Member types | Definition |
---|---|---|
1 | reference | Proxy class that represents a reference to a bit. |
以下是
Sr.No. | Method & Description |
---|---|
1 | bitset::bitset()
Constructs bitset container and initialize it with zero. |
2 | bitset::bitset()
Constructs bitset container and initialize it with the bit value of val. |
3 | bitset::bitset()
Constructs and initializes a bitset container from C++ string object. |
4 | bitset::bitset()
Constructs and initializes a bitset container from c-style string. |
Sr.No. | Method & Description |
---|---|
1 | bitset::reference()
This is embedded class which provides l-value that can be returned from std::bitset::operator[]. |
Sr.No. | Method & Description |
---|---|
1 | bitset::operator&=
Performs bitwise AND operation on current bitset object. |
2 | bitset::operator|=
Performs bitwise OR operation on current bitset object. |
3 | bitset::operator^=
Performs bitwise XOR operation on current bitset object. |
4 | bitset::operator<<=
Performs bitwise left SHIFT operation on current bitset object. |
5 | bitset::operator>>=
Performs bitwise right SHIFT operation on current bitset object. |
6 | bitset::operator~
Performs bitwise NOT operation on bitset. |
7 | bitset::operator<<
Performs bitwise left SHIFT operation on bitset. |
8 | bitset::operator>>
Performs bitwise right SHIFT operation on bitset. |
9 | bitset::operator==
Test whether two bitsets are equal or not. |
10 | bitset::operator!=
Test whether two bitsets are equal or not. |
11 | bitset::operator&
Performs bitwise AND operation on bitset. |
12 | bitset::operator|
Performs bitwise OR operation on bitset. |
13 | bitset::operator^
Performs bitwise XOR operation on bitset. |
14 | bitset::operator>>
Extracts upto N bits from is and stores into another bitset x. |
15 | bitset::operator>>
Inserts bitset x to the character stream os. |
Sr.No. | Method & Description |
---|---|
1 | bitset::all()
Tests whether all bits from bitset are set or not. |
2 | bitset::any()
Tests whether at least one bit from bitset is set or not. |
3 | bitset::count()
Count number of set bits from bitset. |
4 | bitset::flip() all bits
Toggles all bits from bitset. |
5 | bitset::flip() single bit
Toggles single bit from bitset. |
6 | bitset::none()
Tests whether all bits are unset or not. |
7 | bitset::operator[] bool version
Returns the value of bit at position pos. |
8 | bitset::operator[] reference version
Returns the reference of bit at position pos. |
9 | bitset::reset() all bits
Reset all bits of bitset to zero. |
10 | bitset::reset() single bit
Reset single bit of bitset to zero. |
11 | bitset::set() all bits
Set all bits from bitset to one. |
12 | bitset::set() single bit
Set single bit from bitset to either one or zero. |
13 | bitset::size()
Reports the size of the bitset. |
14 | bitset::test()
Tests whether Nth bit is set or not. |
15 | bitset::to_string()
Converts bitset object to string object. |
16 | bitset::to_ullong()
Convert bitset to unsigned long long. |
17 | bitset::to_ulong()
Convert bitset to unsigned long. |
Sr.No. | Method & Description |
---|---|
1 | bitset::hash()
Returns hash value based on the provided bitset. |