bit::vector
— Add/Remove Elements
We have methods to add or remove single elements from the end of the bit-vector.
1constexpr bit::vector &push(bool one = false);
2constexpr bit::vector &append(bool);
3constexpr bit::vector &pop();
- 1
-
Adds a single element to the end of the bit-vector. The element will default to 0 unless
one == true
. - 2
-
This is a synonym for
push()
and adds a singlebool
to the end of the bit-vector. Several othervector::append
methods exist, so the synonym seems natural. - 3
- Remove the last element from the bit-vector & shrink it if possible; do nothing if the bit-vector is empty.
These methods both return a reference to *this
and can be chained with other calls.
Example
#include <bit/bit.h>
int main()
{
::vector<> v;
bit1.push(true);
vstd::cout << "v: " << v << '\n';
2.push();
vstd::cout << "v: " << v << '\n';
.pop();
vstd::cout << "v: " << v << '\n';
.pop();
vstd::cout << "v: " << v << '\n';
3.pop();
vstd::cout << "v: " << v << '\n';
}
- 1
- Adding a 1 element to the end of the bit-vector.
- 2
- Adding the default element of 0 to the end of the bit-vector.
- 3
-
Calling
pop()
on an empty bit-vector does nothing.
Output
v: [1]
v: [1 0]
v: [1]
v: []
1v: []
- 1
-
Calling
pop()
on an empty vector does nothing.