|
| constexpr | bitset () noexcept |
| | All bits set to zero.
|
| constexpr | bitset (unsigned long long val) noexcept |
| | Initial bits bitwise-copied from a single word (others set to zero).
|
| template<class _CharT, class _Traits, class _Alloc> |
| | bitset (const std::basic_string< _CharT, _Traits, _Alloc > &s, size_t position=0) |
| | Use a subset of a string.
|
| template<class _CharT, class _Traits, class _Alloc> |
| | bitset (const std::basic_string< _CharT, _Traits, _Alloc > &s, size_t position, size_t n) |
| | Use a subset of a string.
|
| 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<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')) |
| | Construct from a character array.
|
| bitset< Nb > & | operator&= (const bitset< Nb > &rhs) noexcept |
| | Operations on bitsets.
|
| bitset< Nb > & | operator|= (const bitset< Nb > &rhs) noexcept |
| bitset< Nb > & | operator^= (const bitset< Nb > &rhs) noexcept |
| bitset< Nb > & | operator<<= (size_t position) noexcept |
| | Operations on bitsets.
|
| bitset< Nb > & | operator>>= (size_t position) noexcept |
| bitset< Nb > & | Unchecked_set (size_t pos) noexcept |
| | These versions of single-bit set, reset, flip, and test are extensions from the SGI version.
|
| 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 |
| bitset< Nb > & | set () noexcept |
| | Sets every bit to true.
|
| bitset< Nb > & | set (size_t position, bool val=true) |
| | Sets a given bit to a particular value.
|
| bitset< Nb > & | reset () noexcept |
| | Sets every bit to false.
|
| bitset< Nb > & | reset (size_t position) |
| | Sets a given bit to false.
|
| bitset< Nb > & | flip () noexcept |
| | Toggles every bit to its opposite value.
|
| bitset< Nb > & | flip (size_t position) |
| | Toggles a given bit to its opposite value.
|
| bitset< Nb > | operator~ () const noexcept |
| | See the no-argument flip().
|
| reference | operator[] (size_t position) |
| | Array-indexing support.
|
| constexpr bool | operator[] (size_t position) const |
| unsigned long | to_ulong () const |
| | Returns a numerical interpretation of the bitset.
|
| unsigned long long | to_ullong () const |
| template<class _CharT, class _Traits, class _Alloc> |
| std::basic_string< _CharT, _Traits, _Alloc > | to_string () const |
| | Returns a character interpretation of the bitset.
|
| 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 () 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 () 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 () const |
| std::basic_string< char, std::char_traits< char >, std::allocator< char > > | to_string (char zero, char one='1') const |
| 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, _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_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_to_string (std::basic_string< _CharT, _Traits, _Alloc > &s) const |
| size_t | count () const noexcept |
| | Returns the number of bits which are set.
|
| constexpr size_t | size () const noexcept |
| | Returns the total number of bits.
|
| bool | operator== (const bitset< Nb > &rhs) const noexcept |
| | These comparisons for equality/inequality are, well, bitwise.
|
| bool | operator!= (const bitset< Nb > &rhs) const noexcept |
| bool | operator< (const bitset< Nb > &rhs) const noexcept |
| bool | operator<= (const bitset< Nb > &rhs) const noexcept |
| bool | operator> (const bitset< Nb > &rhs) const noexcept |
| bool | operator>= (const bitset< Nb > &rhs) const noexcept |
| int | getMSB () const noexcept |
| bool | increment () noexcept |
| bool | decrement () noexcept |
| template<size_t NbOpnd> |
| bool | add (const bitset< NbOpnd > &a, const bitset< NbOpnd > &b) noexcept |
| template<size_t NbOpnd> |
| bool | add (const bitset< NbOpnd > &a) noexcept |
| | Incremental add.
|
| template<size_t NbOpnd> |
| bool | sub (const bitset< NbOpnd > &a, const bitset< NbOpnd > &b) noexcept |
| template<size_t NbOpnd> |
| bool | sub (const bitset< NbOpnd > &a) noexcept |
| bool | test (size_t position) const |
| | Tests the value of a bit.
|
| bool | all () const noexcept |
| | Tests whether all the bits are on.
|
| bool | any () const noexcept |
| | Tests whether any of the bits are on.
|
| bool | none () const noexcept |
| | Tests whether any of the bits are on.
|
| bitset< Nb > | operator<< (size_t position) const noexcept |
| | Self-explanatory.
|
| bitset< Nb > | operator>> (size_t position) const noexcept |
| size_t | _Find_first () const noexcept |
| | Finds the index of the first "on" bit.
|
| size_t | _Find_next (size_t prev) const noexcept |
| | Finds the index of the next "on" bit after prev.
|
| constexpr | BaseBitset () noexcept |
| constexpr | BaseBitset (unsigned long long val) noexcept |
| constexpr bool | M_testBit (size_t pos) const noexcept |
| WordT & | M_getword (size_t pos) noexcept |
| constexpr WordT | M_getword (size_t pos) const noexcept |
| const WordT * | M_getdata () const noexcept |
| WordT & | M_hiword () noexcept |
| constexpr WordT | M_hiword () const noexcept |
| void | M_do_and (const BaseBitset< Nw > &x) noexcept |
| void | M_do_or (const BaseBitset< Nw > &x) noexcept |
| void | M_do_xor (const BaseBitset< Nw > &x) noexcept |
| void | M_do_left_shift (size_t shift) noexcept |
| void | M_do_right_shift (size_t shift) noexcept |
| void | M_do_flip () noexcept |
| void | M_do_set () noexcept |
| void | M_do_reset () noexcept |
| bool | M_is_equal (const BaseBitset< Nw > &x) const noexcept |
| bool | M_is_less_than (const BaseBitset< Nw > &x) const noexcept |
| | Blocked unsigned less-than operation.
|
| bool | M_is_greater_than (const BaseBitset< Nw > &x) const noexcept |
| | Blocked unsigned greater-than operation.
|
| int | M_getMSB () const noexcept |
| | Finds the position of the highest set bit.
|
| bool | M_increment () noexcept |
| | Increments underlying value by unity.
|
| bool | M_decrement () noexcept |
| | Decrements underlying value by unity.
|
| bool | M_do_add (const BaseBitset< UBB_WORDS(Nb)> &a, const BaseBitset< UBB_WORDS(Nb)> &b) noexcept |
| | Slotwise addtion to this value.
|
| bool | M_do_add (const BaseBitset< UBB_WORDS(Nb)> &a) noexcept |
| | Slotwise increment of this value.
|
| bool | M_do_sub (const BaseBitset< UBB_WORDS(Nb)> &a, const BaseBitset< UBB_WORDS(Nb)> &b) noexcept |
| | Slotwise subtraction into this value.
|
| bool | M_do_sub (const BaseBitset< UBB_WORDS(Nb)> &a) noexcept |
| | Slotwise decrement of this value.
|
| bool | M_are_all () const noexcept |
| bool | M_is_any () const noexcept |
| size_t | M_do_count () const noexcept |
| unsigned long | M_do_to_ulong () const |
| unsigned long long | M_do_to_ullong () const |
| size_t | M_do_find_first (size_t) const noexcept |
| size_t | M_do_find_next (size_t, size_t) const noexcept |
template<size_t Nb>
class universal_bitset::bitset< Nb >
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.
#include <bitset>
#include <iostream>
#include <sstream>
int main()
{
long a = 'a';
cout << "b('a') is " << b << endl;
ostringstream s;
s << b;
string str = s.str();
cout << "index 3 in the string is " << str[3] << " but\n"
<< "index 3 in the bitset is " << b[3] << endl;
}
constexpr bitset() noexcept
All bits set to zero.
Definition ubb.h:1504
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 BaseBitset. The base class works with whole words, not with individual bits. This allows us to specialize BaseBitset 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 BaseBitset is a regular array, and is indexed as such. This is carefully encapsulated.