libstdc++
|
Classes | |
class | reference |
Public Member Functions | |
constexpr | bitset () noexcept |
template<typename _CharT > | |
bitset (const _CharT *__str, typename std::basic_string< _CharT >::size_type __n=std::basic_string< _CharT >::npos, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1')) | |
template<class _CharT , class _Traits , class _Alloc > | |
bitset (const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position, size_t __n) | |
template<class _CharT , class _Traits , class _Alloc > | |
bitset (const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position, size_t __n, _CharT __zero, _CharT __one=_CharT('1')) | |
template<class _CharT , class _Traits , class _Alloc > | |
bitset (const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position=0) | |
constexpr | bitset (unsigned long long __val) noexcept |
size_t | _Find_first () const noexcept |
size_t | _Find_next (size_t __prev) const noexcept |
template<class _CharT , class _Traits > | |
void | _M_copy_from_ptr (const _CharT *, size_t, size_t, size_t, _CharT, _CharT) |
template<class _CharT , class _Traits , class _Alloc > | |
void | _M_copy_from_string (const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __pos, size_t __n) |
template<class _CharT , class _Traits , class _Alloc > | |
void | _M_copy_from_string (const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __pos, size_t __n, _CharT __zero, _CharT __one) |
template<class _CharT , class _Traits , class _Alloc > | |
void | _M_copy_to_string (std::basic_string< _CharT, _Traits, _Alloc > &, _CharT, _CharT) const |
template<class _CharT , class _Traits , class _Alloc > | |
void | _M_copy_to_string (std::basic_string< _CharT, _Traits, _Alloc > &__s) const |
bool | all () const noexcept |
bool | any () const noexcept |
size_t | count () const noexcept |
bitset< _Nb > & | flip () noexcept |
bitset< _Nb > & | flip (size_t __position) |
bool | none () const noexcept |
bitset< _Nb > | operator~ () const noexcept |
bitset< _Nb > & | reset () noexcept |
bitset< _Nb > & | reset (size_t __position) |
bitset< _Nb > & | set () noexcept |
bitset< _Nb > & | set (size_t __position, bool __val=true) |
constexpr size_t | size () const noexcept |
bool | test (size_t __position) const |
template<class _CharT , class _Traits , class _Alloc > | |
std::basic_string< _CharT, _Traits, _Alloc > | to_string () const |
template<class _CharT , class _Traits > | |
std::basic_string< _CharT, _Traits, std::allocator< _CharT > > | to_string () const |
template<class _CharT > | |
std::basic_string< _CharT, std::char_traits< _CharT >, std::allocator< _CharT > > | to_string () const |
std::basic_string< char, std::char_traits< char >, std::allocator< char > > | to_string () const |
template<class _CharT , class _Traits , class _Alloc > | |
std::basic_string< _CharT, _Traits, _Alloc > | to_string (_CharT __zero, _CharT __one=_CharT('1')) const |
template<class _CharT , class _Traits > | |
std::basic_string< _CharT, _Traits, std::allocator< _CharT > > | to_string (_CharT __zero, _CharT __one=_CharT('1')) const |
template<class _CharT > | |
std::basic_string< _CharT, std::char_traits< _CharT >, std::allocator< _CharT > > | to_string (_CharT __zero, _CharT __one=_CharT('1')) const |
std::basic_string< char, std::char_traits< char >, std::allocator< char > > | to_string (char __zero, char __one='1') const |
unsigned long long | to_ullong () const |
unsigned long | to_ulong () const |
bitset< _Nb > & | operator&= (const bitset< _Nb > &__rhs) noexcept |
bitset< _Nb > & | operator|= (const bitset< _Nb > &__rhs) noexcept |
bitset< _Nb > & | operator^= (const bitset< _Nb > &__rhs) noexcept |
bitset< _Nb > & | operator<<= (size_t __position) noexcept |
bitset< _Nb > & | operator>>= (size_t __position) noexcept |
bitset< _Nb > & | _Unchecked_set (size_t __pos) noexcept |
bitset< _Nb > & | _Unchecked_set (size_t __pos, int __val) noexcept |
bitset< _Nb > & | _Unchecked_reset (size_t __pos) noexcept |
bitset< _Nb > & | _Unchecked_flip (size_t __pos) noexcept |
constexpr bool | _Unchecked_test (size_t __pos) const noexcept |
reference | operator[] (size_t __position) |
constexpr bool | operator[] (size_t __position) const |
bool | operator== (const bitset< _Nb > &__rhs) const noexcept |
bool | operator!= (const bitset< _Nb > &__rhs) const noexcept |
bitset< _Nb > | operator<< (size_t __position) const noexcept |
bitset< _Nb > | operator>> (size_t __position) const noexcept |
Friends | |
class | reference |
struct | std::hash< bitset > |
The bitset class represents a fixed-size sequence of bits.
(Note that bitset does not meet the formal requirements of a container. Mainly, it lacks iterators.)
The template argument, Nb, may be any non-negative number, specifying the number of bits (e.g., "0", "12", "1024*1024").
In the general unoptimized case, storage is allocated in word-sized blocks. Let B be the number of bits in a word, then (Nb+(B-1))/B words will be used for storage. B - NbB bits are unused. (They are the high-order bits in the highest word.) It is a class invariant that those unused bits are always zero.
If you think of bitset as a simple array of bits, be aware that your mental picture is reversed: a bitset behaves the same way as bits in integers do, with the bit at index 0 in the least significant / right-hand position, and the bit at index Nb-1 in the most significant / left-hand position. Thus, unlike other containers, a bitset's index counts from right to left, to put it very loosely.
This behavior is preserved when translating to and from strings. For example, the first line of the following program probably prints b('a') is 0001100001 on a modern ASCII system.
Also see: https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_containers.html for a description of extensions.
Most of the actual code isn't contained in bitset<> itself, but in the base class _Base_bitset. The base class works with whole words, not with individual bits. This allows us to specialize _Base_bitset for the important special case where the bitset is only a single word.
Extra confusion can result due to the fact that the storage for _Base_bitset is a regular array, and is indexed as such. This is carefully encapsulated.
Definition at line 751 of file std/bitset.
|
inlineconstexprnoexcept |
All bits set to zero.
Definition at line 869 of file std/bitset.
|
inlineconstexprnoexcept |
Initial bits bitwise-copied from a single word (others set to zero).
Definition at line 874 of file std/bitset.
|
inlineexplicit |
Use a subset of a string.
__s | A string of 0 and 1 characters. |
__position | Index of the first character in __s to use; defaults to zero. |
std::out_of_range | If pos is bigger the size of __s. |
std::invalid_argument | If a character appears in the string which is neither 0 nor 1. |
Definition at line 893 of file std/bitset.
|
inline |
Use a subset of a string.
__s | A string of 0 and 1 characters. |
__position | Index of the first character in __s to use. |
__n | The number of characters to copy. |
std::out_of_range | If __position is bigger the size of __s. |
std::invalid_argument | If a character appears in the string which is neither 0 nor 1. |
Definition at line 914 of file std/bitset.
|
inline |
Definition at line 925 of file std/bitset.
|
inlineexplicit |
Construct from a character array.
__str | An array of characters zero and one. |
__n | The number of characters to use. |
__zero | The character corresponding to the value 0. |
__one | The character corresponding to the value 1. |
std::invalid_argument | If a character appears in the string which is neither __zero nor __one. |
Definition at line 946 of file std/bitset.
void bitset::_M_copy_from_ptr | ( | const _CharT * | __s, |
size_t | __len, | ||
size_t | __pos, | ||
size_t | __n, | ||
_CharT | __zero, | ||
_CharT | __one | ||
) |
Definition at line 1392 of file std/bitset.
|
inline |
Definition at line 1284 of file std/bitset.
|
inline |
Definition at line 1270 of file std/bitset.
void bitset::_M_copy_to_string | ( | std::basic_string< _CharT, _Traits, _Alloc > & | __s, |
_CharT | __zero, | ||
_CharT | __one | ||
) | const |
Definition at line 1413 of file std/bitset.
|
inline |
Definition at line 1290 of file std/bitset.
|
inlinenoexcept |
Tests whether all the bits are on.
Definition at line 1336 of file std/bitset.
|
inlinenoexcept |
Tests whether any of the bits are on.
Definition at line 1344 of file std/bitset.
|
inlinenoexcept |
Returns the number of bits which are set.
Definition at line 1295 of file std/bitset.
|
inlinenoexcept |
Toggles every bit to its opposite value.
Definition at line 1123 of file std/bitset.
Referenced by std::bitset< _Nb >::operator~().
|
inline |
Toggles a given bit to its opposite value.
__position | The index of the bit. |
std::out_of_range | If pos is bigger the size of the set. |
Definition at line 1136 of file std/bitset.
|
inlinenoexcept |
Tests whether any of the bits are on.
Definition at line 1352 of file std/bitset.
|
inlinenoexcept |
These comparisons for equality/inequality are, well, bitwise.
Definition at line 1311 of file std/bitset.
|
inlinenoexcept |
Operations on bitsets.
__rhs | A same-sized bitset. |
These should be self-explanatory.
Definition at line 972 of file std/bitset.
|
inlinenoexcept |
Self-explanatory.
Definition at line 1352 of file std/bitset.
|
inlinenoexcept |
Operations on bitsets.
__position | The number of places to shift. |
These should be self-explanatory.
Definition at line 986 of file std/bitset.
|
inlinenoexcept |
These comparisons for equality/inequality are, well, bitwise.
Definition at line 1306 of file std/bitset.
|
inlinenoexcept |
Self-explanatory.
Definition at line 1362 of file std/bitset.
|
inlinenoexcept |
Operations on bitsets.
__position | The number of places to shift. |
These should be self-explanatory.
Definition at line 1014 of file std/bitset.
|
inline |
Array-indexing support.
__position | Index into the bitset. |
_GLIBCXX_RESOLVE_LIB_DEFECTS Note that this implementation already resolves DR 11 (items 1 and 2), but does not do the range-checking required by that DR's resolution. -pme The DR has since been changed: range-checking is a precondition (users' responsibility), and these functions must not throw. -pme
Definition at line 1163 of file std/bitset.
|
inlineconstexpr |
Array-indexing support.
__position | Index into the bitset. |
_GLIBCXX_RESOLVE_LIB_DEFECTS Note that this implementation already resolves DR 11 (items 1 and 2), but does not do the range-checking required by that DR's resolution. -pme The DR has since been changed: range-checking is a precondition (users' responsibility), and these functions must not throw. -pme
Definition at line 1167 of file std/bitset.
|
inlinenoexcept |
Operations on bitsets.
__rhs | A same-sized bitset. |
These should be self-explanatory.
Definition at line 986 of file std/bitset.
|
inlinenoexcept |
Operations on bitsets.
__rhs | A same-sized bitset. |
These should be self-explanatory.
Definition at line 979 of file std/bitset.
|
inlinenoexcept |
See the no-argument flip().
Definition at line 1144 of file std/bitset.
References std::bitset< _Nb >::flip().
|
inlinenoexcept |
Sets every bit to false.
Definition at line 1099 of file std/bitset.
|
inline |
Sets a given bit to false.
__position | The index of the bit. |
std::out_of_range | If pos is bigger the size of the set. |
Same as writing set(pos,false)
.
Definition at line 1113 of file std/bitset.
|
inlinenoexcept |
Sets every bit to true.
Definition at line 1075 of file std/bitset.
|
inline |
Sets a given bit to a particular value.
__position | The index of the bit. |
__val | Either true or false, defaults to true. |
std::out_of_range | If pos is bigger the size of the set. |
Definition at line 1089 of file std/bitset.
|
inlineconstexprnoexcept |
Returns the total number of bits.
Definition at line 1300 of file std/bitset.
|
inline |
Tests the value of a bit.
__position | The index of a bit. |
std::out_of_range | If pos is bigger the size of the set. |
Definition at line 1323 of file std/bitset.
|
inline |
Returns a character interpretation of the bitset.
Note the ordering of the bits: decreasing character positions correspond to increasing bit positions (see the main class notes for an example).
Definition at line 1197 of file std/bitset.
|
inline |
Definition at line 1219 of file std/bitset.
|
inline |
Definition at line 1233 of file std/bitset.
|
inline |
Definition at line 1249 of file std/bitset.
|
inline |
Definition at line 1208 of file std/bitset.
|
inline |
Definition at line 1226 of file std/bitset.
|
inline |
Definition at line 1242 of file std/bitset.
|
inline |
Definition at line 1256 of file std/bitset.
|
inline |
Definition at line 1183 of file std/bitset.
|
inline |
Returns a numerical interpretation of the bitset.
std::overflow_error | If there are too many bits to be represented in an unsigned long . |
Definition at line 1178 of file std/bitset.
|
friend |
Definition at line 865 of file std/bitset.
Definition at line 779 of file std/bitset.