libstdc++
|
Classes | |
class | reference |
Public Types | |
typedef __dynamic_bitset_base< _WordT, _Alloc > | _Base |
typedef _Alloc | allocator_type |
typedef _WordT | block_type |
typedef bool | const_reference |
typedef size_t | size_type |
Public Member Functions | |
dynamic_bitset ()=default | |
dynamic_bitset (const allocator_type &__alloc) | |
dynamic_bitset (const char *__str, const allocator_type &__alloc=allocator_type()) | |
dynamic_bitset (const dynamic_bitset &)=default | |
template<typename _CharT , typename _Traits , typename _Alloc1 > | |
dynamic_bitset (const std::basic_string< _CharT, _Traits, _Alloc1 > &__str, typename basic_string< _CharT, _Traits, _Alloc1 >::size_type __pos=0, typename basic_string< _CharT, _Traits, _Alloc1 >::size_type __n=std::basic_string< _CharT, _Traits, _Alloc1 >::npos, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1'), const allocator_type &__alloc=allocator_type()) | |
dynamic_bitset (dynamic_bitset &&__b) noexcept | |
dynamic_bitset (initializer_list< block_type > __il, const allocator_type &__alloc=allocator_type()) | |
dynamic_bitset (size_type __nbits, unsigned long long __val=0ULL, const allocator_type &__alloc=allocator_type()) | |
template<typename _Traits = std::char_traits<char>, typename _CharT = typename _Traits::char_type> | |
void | _M_copy_from_ptr (const _CharT *, size_t, size_t, size_t, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1')) |
template<typename _CharT , typename _Traits , typename _Alloc1 > | |
void | _M_copy_from_string (const basic_string< _CharT, _Traits, _Alloc1 > &__str, size_t __pos, size_t __n, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1')) |
template<typename _CharT , typename _Traits , typename _Alloc1 > | |
void | _M_copy_to_string (std::basic_string< _CharT, _Traits, _Alloc1 > &__str, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1')) const |
bool | all () const |
bool | any () const |
template<typename _BlockInputIterator > | |
void | append (_BlockInputIterator __first, _BlockInputIterator __last) |
void | append (block_type __block) |
void | append (initializer_list< block_type > __il) |
void | clear () |
size_type | count () const noexcept |
bool | empty () const noexcept |
size_type | find_first () const |
size_type | find_next (size_t __prev) const |
dynamic_bitset & | flip () |
dynamic_bitset & | flip (size_type __pos) |
allocator_type | get_allocator () const noexcept |
bool | is_proper_subset_of (const dynamic_bitset &__b) const |
bool | is_subset_of (const dynamic_bitset &__b) const |
constexpr size_type | max_size () noexcept |
bool | none () const |
size_type | num_blocks () const noexcept |
dynamic_bitset & | operator= (const dynamic_bitset &)=default |
dynamic_bitset & | operator= (dynamic_bitset &&__b) noexcept(std::is_nothrow_move_assignable< _Base >::value) |
dynamic_bitset | operator~ () const |
void | push_back (bool __bit) |
dynamic_bitset & | reset () |
dynamic_bitset & | reset (size_type __pos) |
void | resize (size_type __nbits, bool __value=false) |
dynamic_bitset & | set () |
dynamic_bitset & | set (size_type __pos, bool __val=true) |
size_type | size () const noexcept |
void | swap (dynamic_bitset &__b) noexcept |
bool | test (size_type __pos) const |
template<typename _CharT = char, typename _Traits = std::char_traits<_CharT>, typename _Alloc1 = std::allocator<_CharT>> | |
std::basic_string< _CharT, _Traits, _Alloc1 > | to_string (_CharT __zero=_CharT('0'), _CharT __one=_CharT('1')) const |
unsigned long long | to_ullong () const |
unsigned long | to_ulong () const |
dynamic_bitset & | operator&= (const dynamic_bitset &__rhs) |
dynamic_bitset & | operator&= (dynamic_bitset &&__rhs) |
dynamic_bitset & | operator|= (const dynamic_bitset &__rhs) |
dynamic_bitset & | operator^= (const dynamic_bitset &__rhs) |
dynamic_bitset & | operator-= (const dynamic_bitset &__rhs) |
dynamic_bitset & | operator<<= (size_type __pos) |
dynamic_bitset & | operator>>= (size_type __pos) |
reference | operator[] (size_type __pos) |
const_reference | operator[] (size_type __pos) const |
dynamic_bitset | operator<< (size_type __pos) const |
dynamic_bitset | operator>> (size_type __pos) const |
Static Public Attributes | |
static const size_type | bits_per_block |
static const size_type | npos |
Friends | |
bool | operator< (const dynamic_bitset &__lhs, const dynamic_bitset &__rhs) noexcept |
bool | operator== (const dynamic_bitset &__lhs, const dynamic_bitset &__rhs) noexcept |
class | reference |
The dynamic_bitset class represents a sequence of bits.
See N2050, Proposal to Add a Dynamically Sizeable Bitset to the Standard Library. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2050.pdf
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 dynamic_bitset as "a simple array of bits," be aware that your mental picture is reversed: a dynamic_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 dynamic_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.
Most of the actual code isn't contained in dynamic_bitset<> itself, but in the base class __dynamic_bitset_base. The base class works with whole words, not with individual bits. This allows us to specialize __dynamic_bitset_base for the important special case where the dynamic_bitset is only a single word.
Extra confusion can result due to the fact that the storage for __dynamic_bitset_base is a vector, and is indexed as such. This is carefully encapsulated.
Definition at line 419 of file dynamic_bitset.
typedef __dynamic_bitset_base<_WordT, _Alloc> std::tr2::dynamic_bitset< _WordT, _Alloc >::_Base |
Definition at line 427 of file dynamic_bitset.
typedef _Alloc std::tr2::dynamic_bitset< _WordT, _Alloc >::allocator_type |
Definition at line 429 of file dynamic_bitset.
typedef _WordT std::tr2::dynamic_bitset< _WordT, _Alloc >::block_type |
Definition at line 428 of file dynamic_bitset.
typedef bool std::tr2::dynamic_bitset< _WordT, _Alloc >::const_reference |
Definition at line 569 of file dynamic_bitset.
typedef size_t std::tr2::dynamic_bitset< _WordT, _Alloc >::size_type |
Definition at line 430 of file dynamic_bitset.
|
default |
All bits set to zero.
|
inlineexplicit |
All bits set to zero.
Definition at line 578 of file dynamic_bitset.
|
inlineexplicit |
Initial bits bitwise-copied from a single word (others set to zero).
Definition at line 584 of file dynamic_bitset.
|
inline |
Definition at line 590 of file dynamic_bitset.
|
inlineexplicit |
Use a subset of a string.
__str | A string of '0' and '1' characters. |
__pos | Index of the first character in __str to use. |
__n | The number of characters to copy. |
__zero | The character to use for unset bits. |
__one | The character to use for set bits. |
__alloc | An allocator. |
std::out_of_range | If __pos is bigger the size of __str . |
std::invalid_argument | If a character appears in the string which is neither '0' nor '1'. |
Definition at line 609 of file dynamic_bitset.
|
inlineexplicit |
Construct from a string.
__str | A string of '0' and '1' characters. |
__alloc | An allocator. |
std::invalid_argument | If a character appears in the string which is neither '0' nor '1'. |
Definition at line 636 of file dynamic_bitset.
|
default |
Copy constructor.
|
inlinenoexcept |
Move constructor.
Definition at line 648 of file dynamic_bitset.
void std::tr2::dynamic_bitset< _WordT, _Alloc >::_M_copy_from_ptr | ( | const _CharT * | __str, |
size_t | __len, | ||
size_t | __pos, | ||
size_t | __n, | ||
_CharT | __zero = _CharT('0') , |
||
_CharT | __one = _CharT('1') |
||
) |
Definition at line 179 of file dynamic_bitset.tcc.
|
inline |
Definition at line 975 of file dynamic_bitset.
|
inline |
Tests whether all the bits are on.
Definition at line 1036 of file dynamic_bitset.
|
inline |
Tests whether any of the bits are on.
Definition at line 1044 of file dynamic_bitset.
|
inline |
Append an iterator range of blocks.
Definition at line 744 of file dynamic_bitset.
|
inline |
Append a block.
Definition at line 726 of file dynamic_bitset.
|
inline |
Definition at line 736 of file dynamic_bitset.
|
inline |
Clear the bitset.
Definition at line 701 of file dynamic_bitset.
|
inlinenoexcept |
Returns the number of bits which are set.
Definition at line 992 of file dynamic_bitset.
|
inlinenoexcept |
Returns true if the dynamic_bitset is empty.
Definition at line 1007 of file dynamic_bitset.
|
inline |
Finds the index of the first "on" bit.
Definition at line 1072 of file dynamic_bitset.
|
inline |
Finds the index of the next "on" bit after prev.
__prev | Where to start searching. |
Definition at line 1082 of file dynamic_bitset.
|
inline |
Toggles every bit to its opposite value.
Definition at line 883 of file dynamic_bitset.
|
inline |
Toggles a given bit to its opposite value.
__pos | The index of the bit. |
std::out_of_range | If __pos is bigger the size of the set. |
Definition at line 896 of file dynamic_bitset.
|
inlinenoexcept |
Return the allocator for the bitset.
Definition at line 681 of file dynamic_bitset.
|
inline |
Definition at line 1090 of file dynamic_bitset.
|
inline |
Definition at line 1086 of file dynamic_bitset.
|
inlineconstexprnoexcept |
Returns the maximum size of a dynamic_bitset object having the same type as *this. The real answer is max() * bits_per_block but is likely to overflow.
Definition at line 1014 of file dynamic_bitset.
|
inline |
Tests whether any of the bits are on.
Definition at line 1052 of file dynamic_bitset.
|
inlinenoexcept |
Returns the total number of blocks.
Definition at line 1002 of file dynamic_bitset.
|
inline |
Operations on dynamic_bitsets.
__rhs | A same-sized dynamic_bitset. |
These should be self-explanatory.
Definition at line 759 of file dynamic_bitset.
|
inline |
Operations on dynamic_bitsets.
__rhs | A same-sized dynamic_bitset. |
These should be self-explanatory.
Definition at line 766 of file dynamic_bitset.
|
inline |
Operations on dynamic_bitsets.
__rhs | A same-sized dynamic_bitset. |
These should be self-explanatory.
Definition at line 787 of file dynamic_bitset.
|
inline |
Self-explanatory.
Definition at line 1057 of file dynamic_bitset.
|
inline |
Operations on dynamic_bitsets.
__pos | The number of places to shift. |
These should be self-explanatory.
Definition at line 801 of file dynamic_bitset.
|
default |
Copy assignment operator.
|
inlinenoexcept |
Move assignment operator.
Definition at line 665 of file dynamic_bitset.
|
inline |
Self-explanatory.
Definition at line 1062 of file dynamic_bitset.
|
inline |
Operations on dynamic_bitsets.
__pos | The number of places to shift. |
These should be self-explanatory.
Definition at line 815 of file dynamic_bitset.
|
inline |
Array-indexing support.
__pos | Index into the dynamic_bitset. |
Definition at line 918 of file dynamic_bitset.
|
inline |
Array-indexing support.
__pos | Index into the dynamic_bitset. |
Definition at line 922 of file dynamic_bitset.
|
inline |
Operations on dynamic_bitsets.
__rhs | A same-sized dynamic_bitset. |
These should be self-explanatory.
Definition at line 780 of file dynamic_bitset.
|
inline |
Operations on dynamic_bitsets.
__rhs | A same-sized dynamic_bitset. |
These should be self-explanatory.
Definition at line 773 of file dynamic_bitset.
|
inline |
See the no-argument flip().
Definition at line 905 of file dynamic_bitset.
|
inline |
Push a bit onto the high end of the bitset.
Definition at line 711 of file dynamic_bitset.
|
inline |
Sets every bit to false.
Definition at line 858 of file dynamic_bitset.
|
inline |
Sets a given bit to false.
__pos | 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 872 of file dynamic_bitset.
|
inline |
Resize the bitset.
Definition at line 688 of file dynamic_bitset.
Referenced by std::tr2::operator>>().
|
inline |
Sets every bit to true.
Definition at line 833 of file dynamic_bitset.
|
inline |
Sets a given bit to a particular value.
__pos | 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 847 of file dynamic_bitset.
|
inlinenoexcept |
Returns the total number of bits.
Definition at line 997 of file dynamic_bitset.
Referenced by std::tr2::operator>>().
|
inlinenoexcept |
Swap with another bitset.
Definition at line 654 of file dynamic_bitset.
|
inline |
Tests the value of a bit.
__pos | The index of a bit. |
std::out_of_range | If __pos is bigger the size of the set. |
Definition at line 1024 of file dynamic_bitset.
|
inline |
Returns a character interpretation of the dynamic_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 958 of file dynamic_bitset.
|
inline |
Returns a numerical interpretation of the dynamic_bitset.
std::overflow_error | If there are too many bits to be represented in an unsigned long . |
Definition at line 943 of file dynamic_bitset.
|
inline |
Returns a numerical interpretation of the dynamic_bitset.
std::overflow_error | If there are too many bits to be represented in an unsigned long . |
Definition at line 933 of file dynamic_bitset.
|
friend |
Definition at line 1098 of file dynamic_bitset.
|
friend |
Definition at line 1094 of file dynamic_bitset.
|
friend |
Definition at line 567 of file dynamic_bitset.
|
static |
Definition at line 432 of file dynamic_bitset.
|
static |
Definition at line 434 of file dynamic_bitset.