[#BloombergLP-bdlc-BitArray]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlc.adoc[bdlc]::BitArray
:relfileprefix: ../../
:mrdocs:

This class implements an efficient, value&hyphen;semantic array of boolean (a&period;k&period;a&period; bit, i&period;e&period;, binary digit) values stored in contiguous memory&period; The physical capacity of this array may grow, but never shrinks&period; Capacity may be reserved initially via a constructor, or at any time thereafter by using the `reserveCapacity` method&semi; otherwise, capacity will be increased automatically as needed&period; Note that capacity is not a _salient_ attribute of this object, and, as such, does not contribute to overall value&period; Also note that this class provides an implicit no&hyphen;throw guarantee for all methods (including manipulators) that do not attempt to alter capacity&period;

== Synopsis

Declared in `&lt;bdlc&lowbar;bitarray&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class BitArray;
----

== Enums

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlc/BitArray/_04enum.adoc[`Unnamed enum`] 
| Constants describing the storage representation of a `BitArray`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlc/BitArray/2constructor-011.adoc[`BitArray`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bdlc/BitArray/2destructor.adoc[`&#126;BitArray`] [.small]#[destructor]#
| Destroy this object&period;
| xref:BloombergLP/bdlc/BitArray/operator_assign.adoc[`operator&equals;`] 
| Assign to this array the value of the specified `rhs` array, and return a non&hyphen;`const` reference to this array&period;
| xref:BloombergLP/bdlc/BitArray/allocator.adoc[`allocator`] 
| Return the allocator used by this object to supply memory&period;
| xref:BloombergLP/bdlc/BitArray/andEqual-04.adoc[`andEqual`] 
| `andEqual` overloads
| xref:BloombergLP/bdlc/BitArray/append-0b.adoc[`append`] 
| `append` overloads
| xref:BloombergLP/bdlc/BitArray/assign-01.adoc[`assign`] 
| `assign` overloads
| xref:BloombergLP/bdlc/BitArray/assign0-00.adoc[`assign0`] 
| `assign0` overloads
| xref:BloombergLP/bdlc/BitArray/assign1-0d.adoc[`assign1`] 
| `assign1` overloads
| xref:BloombergLP/bdlc/BitArray/assignAll.adoc[`assignAll`] 
| Set all bits in this array to the specified `value`&period;
| xref:BloombergLP/bdlc/BitArray/assignAll0.adoc[`assignAll0`] 
| Set to 0 the value of every bit in this array&period;
| xref:BloombergLP/bdlc/BitArray/assignAll1.adoc[`assignAll1`] 
| Set to 1 the value of every bit in this array&period;
| xref:BloombergLP/bdlc/BitArray/assignBits.adoc[`assignBits`] 
| Assign the low&hyphen;order specified `numBits` from the specified `srcBits` to this object, starting at the specified `index`&period; The behavior is undefined unless `numBits &lt;&equals; k&lowbar;BITS&lowbar;PER&lowbar;UINT64` and `index &plus; numBits &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/bdexStreamIn.adoc[`bdexStreamIn`] 
| Assign to this object the value read from the specified input `stream` using the specified `version` format, and return a reference to `stream`&period; If `stream` is initially invalid, this operation has no effect&period; If `version` is not supported, this object is unaltered and `stream` is invalidated, but otherwise unmodified&period; If `version` is supported but `stream` becomes invalid during this operation, this object has an undefined, but valid, state&period; Note that no version is read from `stream`&period; See the `bslx` package&hyphen;level documentation for more information on BDEX streaming of value&hyphen;semantic types and containers&period;
| xref:BloombergLP/bdlc/BitArray/bdexStreamOut.adoc[`bdexStreamOut`] 
| Write the value of this object, using the specified `version` format, to the specified output `stream`, and return a reference to `stream`&period; If `stream` is initially invalid, this operation has no effect&period; If `version` is not supported, `stream` is invalidated, but otherwise unmodified&period; Note that `version` is not written to `stream`&period; See the `bslx` package&hyphen;level documentation for more information on BDEX streaming of value&hyphen;semantic types and containers&period;
| xref:BloombergLP/bdlc/BitArray/bits.adoc[`bits`] 
| Return the specified `numBits` beginning at the specified `index` in this array as the low&hyphen;order bits of the returned value&period; The behavior is undefined unless `numBits &lt;&equals; sizeof(uint64&lowbar;t) &ast; CHAR&lowbar;BIT` and `index &plus; numBits &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/find0AtMaxIndex.adoc[`find0AtMaxIndex`] 
| Return the index of the most&hyphen;significant 0 bit in this array in the range optionally specified by `begin` and `end`, and `k&lowbar;INVALID&lowbar;INDEX` otherwise&period; The range is `&lsqb;begin &period;&period; effectiveEnd)&rsqb;`, where `effectiveEnd &equals;&equals; length()` if `end` is not specified and `effectiveEnd &equals;&equals; end` otherwise&period; The behavior is undefined unless `begin &lt;&equals; effectiveEnd &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/find0AtMinIndex.adoc[`find0AtMinIndex`] 
| Return the index of the least&hyphen;significant 0 bit in this array in the range optionally specified by `begin` and `end`, and `k&lowbar;INVALID&lowbar;INDEX` otherwise&period; The range is `&lsqb;begin &period;&period; effectiveEnd)&rsqb;`, where `effectiveEnd &equals;&equals; length()` if `end` is not specified and `effectiveEnd &equals;&equals; end` otherwise&period; The behavior is undefined unless `begin &lt;&equals; effectiveEnd &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/find1AtMaxIndex.adoc[`find1AtMaxIndex`] 
| Return the index of the most&hyphen;significant 1 bit in this array in the range optionally specified by `begin` and `end`, and `k&lowbar;INVALID&lowbar;INDEX` otherwise&period; The range is `&lsqb;begin &period;&period; effectiveEnd)&rsqb;`, where `effectiveEnd &equals;&equals; length()` if `end` is not specified and `effectiveEnd &equals;&equals; end` otherwise&period; The behavior is undefined unless `begin &lt;&equals; effectiveEnd &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/find1AtMinIndex.adoc[`find1AtMinIndex`] 
| Return the index of the least&hyphen;significant 1 bit in this array in the range optionally specified by `begin` and `end`, and `k&lowbar;INVALID&lowbar;INDEX` otherwise&period; The range is `&lsqb;begin &period;&period; effectiveEnd)&rsqb;`, where `effectiveEnd &equals;&equals; length()` if `end` is not specified and `effectiveEnd &equals;&equals; end` otherwise&period; The behavior is undefined unless `begin &lt;&equals; effectiveEnd &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/insert-08.adoc[`insert`] 
| `insert` overloads
| xref:BloombergLP/bdlc/BitArray/isAny0.adoc[`isAny0`] 
| Return `true` if the value of any bit in this array is 0, and `false` otherwise&period;
| xref:BloombergLP/bdlc/BitArray/isAny1.adoc[`isAny1`] 
| Return `true` if the value of any bit in this array is 1, and `false` otherwise&period;
| xref:BloombergLP/bdlc/BitArray/isEmpty.adoc[`isEmpty`] 
| Return `true` if the length of this bit array is 0, and `false` otherwise&period;
| xref:BloombergLP/bdlc/BitArray/length.adoc[`length`] 
| Return the number of bits in this array&period;
| xref:BloombergLP/bdlc/BitArray/minusEqual-0c.adoc[`minusEqual`] 
| `minusEqual` overloads
| xref:BloombergLP/bdlc/BitArray/num0.adoc[`num0`] 
| Return the number of bits in the range optionally specified by `begin` and `end` having a value of 0&period; The range is `&lsqb;begin &period;&period; effectiveEnd)&rsqb;`, where `effectiveEnd &equals;&equals; length()` if `end` is not specified and `effectiveEnd &equals;&equals; end` otherwise&period; The behavior is undefined unless `begin &lt;&equals; effectiveEnd &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/num1.adoc[`num1`] 
| Return the number of bits in the range optionally specified by `begin` and `end` having a value of 1&period; The range is `&lsqb;begin &period;&period; effectiveEnd)&rsqb;`, where `effectiveEnd &equals;&equals; length()` if `end` is not specified and `effectiveEnd &equals;&equals; end` otherwise&period; The behavior is undefined unless `begin &lt;&equals; effectiveEnd &lt;&equals; length()`&period;
| xref:BloombergLP/bdlc/BitArray/operator_and_eq.adoc[`operator&amp;&equals;`] 
| Bitwise AND the value of the specified `rhs` array with the value of this array (retaining the results), and return a non&hyphen;`const` reference to this object&period; The length of the result will be the maximum of the lengths of this object and `rhs`, where any most&hyphen;significant bits that are represented in one of the two but not the other will be set to 0&period; Note that `a &amp;&equals; b&semi;` will result in the same value of `a` as `a &equals; a &amp; b&semi;`&period;
| xref:BloombergLP/bdlc/BitArray/operator_minus_eq.adoc[`operator&hyphen;&equals;`] 
| Bitwise MINUS the value of the specified `rhs` array from the value of this array (retaining the results), and return a non&hyphen;`const` reference to this object&period; The length of the result will be the maximum of the lengths of this object and `rhs`&period; If `length() &gt; rhs&period;length()`, the unmatched most&hyphen;significant bits in this array are left unchanged&semi; otherwise, any high&hyphen;order bits of the result that were not present in this object prior to the operation will be set to 0&period; Note that `a &hyphen;&equals; b&semi;` will result in the same value of `a` as `a &equals; a &hyphen; b&semi;` and if `a` and `b` are the same length, `a &hyphen;&equals; b&semi;` will result in the same value of `a` as `a &amp;&equals; &#126;b&semi;` or `a &equals; a &amp; &#126;b&semi;`&period;
| xref:BloombergLP/bdlc/BitArray/operator_lshift_eq.adoc[`operator&lt;&lt;&equals;`] 
| Shift the bits in this array LEFT by the specified `numBits`, filling lower&hyphen;order bits with zeros (retaining the results), and return a non&hyphen;`const` reference to this object&period; The behavior is undefined unless `numBits &lt;&equals; length()`&period; Note that the length of this array is unchanged and the highest&hyphen;order `numBits` are discarded&period;
| xref:BloombergLP/bdlc/BitArray/operator_rshift_eq.adoc[`operator&gt;&gt;&equals;`] 
| Shift the bits in this array RIGHT by the specified `numBits`, filling higher&hyphen;order bits with zeros and discarding low&hyphen;order bits, and return a non&hyphen;`const` reference to this object&period; The behavior is undefined unless `numBits &lt;&equals; length()`&period; Note that the length of this array is unchanged&period;
| xref:BloombergLP/bdlc/BitArray/operator_subs.adoc[`operator&lsqb;&rsqb;`] 
| Return the value of the bit at the specified `index` in this array&period; The behavior is undefined unless `index &lt; length()`&period;
| xref:BloombergLP/bdlc/BitArray/operator_xor_eq.adoc[`operator&circ;&equals;`] 
| Bitwise XOR the value of the specified `rhs` array with the value of this array (retaining the results), and return a non&hyphen;`const` reference to this object&period; If `length() &gt; rhs&period;length()`, the unmatched most&hyphen;significant bits in this array are left unchanged&semi; otherwise, any unmatched most&hyphen;significant bits in `rhs` are propagated to the result without modification&period; Note that `a &circ;&equals; b&semi;` will result in the same value of `a` as `a &equals; a &circ; b&semi;`&period;
| xref:BloombergLP/bdlc/BitArray/operator_or_eq.adoc[`operator&verbar;&equals;`] 
| Bitwise OR the value of the specified `rhs` array with the value of this array (retaining the results), and return a non&hyphen;`const` reference to this object&period; If `length() &gt; rhs&period;length()`, the unmatched most&hyphen;significant bits in this array are left unchanged&semi; otherwise, any unmatched most&hyphen;significant bits in `rhs` are propagated to the result without modification&period; Note that `a &verbar;&equals; b&semi;` will result in the same value of `a` as `a &equals; a &verbar; b&semi;`&period;
| xref:BloombergLP/bdlc/BitArray/orEqual-076.adoc[`orEqual`] 
| `orEqual` overloads
| xref:BloombergLP/bdlc/BitArray/print.adoc[`print`] 
| Format this object to the specified output `stream` at the optionally specified indentation `level` and return a non&hyphen;`const` reference to `stream`&period; If `level` is specified, optionally specify `spacesPerLevel`, the number of spaces per indentation level for this and all of its nested objects&period; Each line is indented by the absolute value of `level &ast; spacesPerLevel`&period; If `level` is negative, suppress indentation of the first line&period; If `spacesPerLevel` is negative, suppress line breaks and format the entire output on one line&period; If `stream` is initially invalid, this operation has no effect&period; Note that a trailing newline is provided in multiline mode only&period;
| xref:BloombergLP/bdlc/BitArray/remove-09.adoc[`remove`] 
| `remove` overloads
| xref:BloombergLP/bdlc/BitArray/removeAll.adoc[`removeAll`] 
| Remove all of the bits in this array, leaving the length 0, but having no effect on capacity&period;
| xref:BloombergLP/bdlc/BitArray/reserveCapacity.adoc[`reserveCapacity`] 
| Reserve sufficient internal capacity to accommodate a length of at least the specified `numBits` without reallocation&period; If an exception is thrown during this reallocation attempt (i&period;e&period;, by the memory allocator indicated at construction) the value of this array is guaranteed to be unchanged&period;
| xref:BloombergLP/bdlc/BitArray/rotateLeft.adoc[`rotateLeft`] 
| Shift the values in this array to the left by the specified `numBits` positions, with the high&hyphen;order values &quot;rotating&quot; into the low&hyphen;order bits&period; The behavior is undefined unless `numBits &lt;&equals; length()`&period; Note that the length of this array remains unchanged&period;
| xref:BloombergLP/bdlc/BitArray/rotateRight.adoc[`rotateRight`] 
| Shift the values in this array to the right by the specified `numBits` positions, with the low&hyphen;order values &quot;rotating&quot; into the high&hyphen;order bits&period; The behavior is undefined unless `numBits &lt;&equals; length()`&period; Note that the length of this array remains unchanged&period;
| xref:BloombergLP/bdlc/BitArray/setLength.adoc[`setLength`] 
| Set the number of bits in this array to the specified `newLength`&period; If `newLength &lt; length()`, bits at index positions at or above `newLength` are removed&semi; otherwise, any new bits (at or above the current length) are initialized to the optionally specified `value`, or to 0 if `value` is not specified&period;
| xref:BloombergLP/bdlc/BitArray/swap.adoc[`swap`] 
| Efficiently exchange the value of this object with the value of the specified `other` object&period; This method provides the no&hyphen;throw exception&hyphen;safety guarantee&period; The behavior is undefined unless this object was created with the same allocator as `other`&period;
| xref:BloombergLP/bdlc/BitArray/swapBits.adoc[`swapBits`] 
| Efficiently exchange the values of the bits at the specified `index1` and `index2` indices&period; The behavior is undefined unless `index1 &lt; length()` and `index2 &lt; length()`&period;
| xref:BloombergLP/bdlc/BitArray/toggle-0d1.adoc[`toggle`] 
| `toggle` overloads
| xref:BloombergLP/bdlc/BitArray/toggleAll.adoc[`toggleAll`] 
| Complement the value of every bit in this array&period; Note that the behavior is analogous to applying the `&#126;` operator to an object of fundamental type `unsigned int`&period;
| xref:BloombergLP/bdlc/BitArray/xorEqual-0e.adoc[`xorEqual`] 
| `xorEqual` overloads
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlc/BitArray/maxSupportedBdexVersion-07.adoc[`maxSupportedBdexVersion`] 
| `maxSupportedBdexVersion` overloads
|===


== Static Data Members

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlc/BitArray/k_INVALID_INDEX.adoc[`k&lowbar;INVALID&lowbar;INDEX`] 
| Sentinel index value indicating an invalid bit position&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:BloombergLP/bdlc/operator_eq-04d.adoc[BloombergLP::bdlc::operator&equals;&equals;]`
| Return `true` if the specified `lhs` and `rhs` arrays have the same value, and `false` otherwise&period; Two arrays have the same value if they have the same length, and corresponding bits at each bit position have the same value&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlc/operator_not_eq-008.adoc[`operator!&equals;`]
| Return `true` if the specified `lhs` and `rhs` arrays do not have the same value, and `false` otherwise&period; Two arrays do not have the same value if they do not have the same length, or there is at least one valid index position at which corresponding bits do not have the same value&period;
| xref:BloombergLP/bdlc/operator_bitand.adoc[`operator&amp;`]
| Return the value that is the bitwise AND of the specified `lhs` and `rhs` arrays&period; The length of the resulting bit array will be the maximum of that of `lhs` and `rhs`, with any unmatched high&hyphen;order bits set to 0&period; Note that this behavior is consistent with zero&hyphen;extending a copy of the shorter array&period;
| xref:BloombergLP/bdlc/operator_minus-0a9.adoc[`operator&hyphen;`]
| Return the value that is the bitwise MINUS of the specified `lhs` and `rhs` arrays&period; The length of the resulting bit array will be the maximum of that of `lhs` and `rhs`, with any unmatched high&hyphen;order `lhs` bits copied unchanged, and any unmatched high&hyphen;order `rhs` bits set to 0&period; Note that this behavior is consistent with zero&hyphen;extending a copy of the shorter array&period;
| xref:BloombergLP/bdlc/operator_lshift-0688.adoc[`operator&lt;&lt;`]
| Return the value of the specified `array` left&hyphen;shifted by the specified `numBits` positions, having filled the lower&hyphen;index positions with zeros&period; The behavior is undefined unless `numBits &lt;&equals; array&period;length()`&period; Note that the length of the result equals the length of the original array, and that the highest&hyphen;order `numBits` are discarded in the result&period;
| xref:BloombergLP/bdlc/operator_rshift.adoc[`operator&gt;&gt;`]
| Return the value of the specified `array` right&hyphen;shifted by the specified `numBits` positions, having filled the higher&hyphen;index positions with zeros&period; The behavior is undefined unless `numBits &lt;&equals; array&period;length()`&period; Note that the length of the result equals the length of the original array, and that the lowest&hyphen;order `numBits` are discarded in the result&period;
| xref:BloombergLP/bdlc/operator_xor.adoc[`operator&circ;`]
| Return the value that is the bitwise XOR of the specified `lhs` and `rhs` arrays&period; The length of the resulting bit array will be the maximum of that of `lhs` and `rhs`, with any unmatched high&hyphen;order bits copied unchanged&period; Note that this behavior is consistent with zero&hyphen;extending a copy of the shorter array&period;
| xref:BloombergLP/bdlc/operator_bitor.adoc[`operator&verbar;`]
| Return the value that is the bitwise OR of the specified `lhs` and `rhs` arrays&period; The length of the resulting bit array will be the maximum of that of `lhs` and `rhs`, with any unmatched high&hyphen;order bits copied unchanged&period; Note that this behavior is consistent with zero&hyphen;extending a copy of the shorter array&period;
| xref:BloombergLP/bdlc/operator_bitnot.adoc[`operator&#126;`]
| Return the bitwise complement (&quot;toggle&quot;) of the specified `array`&period;
| xref:BloombergLP/bdlc/swap-00b.adoc[`swap`]
| Exchange the values of the specified `a` and `b` objects&period; This function provides the no&hyphen;throw exception&hyphen;safety guarantee if the two objects were created with the same allocator and the basic guarantee otherwise&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
