GF2::Vector — Resize a Bit-Vector
Resizes the bit-vector. Any added elements are initialized to 0.
constexpr Vector &resize(std::size_t n);
If n < size() the bit-vector is reduced in size to the first n elements.
If n > size() extra 0’s are appended to the bit-vector to get it up to size n.
This method returns a reference to *this so it can be chained with other calls.
Example
#include <GF2/GF2.h>
int main()
{
GF2::Vector<uint8_t> v("10101010"); (1)
std::cout << v << ":\t size " << v.size() << ", capacity " << v.capacity() << '\n';
v.resize(12); (2)
std::cout << v << ":\t size " << v.size() << ", capacity " << v.capacity() << '\n';
v.resize(8); (3)
std::cout << v << ":\t size " << v.size() << ", capacity " << v.capacity() << '\n';
}
| 1 | Construct a bit-vector of size 8 where the underlying block size is just 8 bits. |
| 2 | Resize the bit-vector to have 12 elements. The extra 4 will be initialized to 0’s. |
| 3 | Resize the bit-vector back down to the original 8 elements. |
Output
10101010: size 8, capacity 8
101010100000: size 12, capacity 16
10101010: size 8, capacity 16
See Also