Creating a boost dynamic_bitset vector in C ++

I want to create an array of dynamic_bitsets. So I created a dynamic_bitset vector using

vector<boost::dynamic_bitset<>> v;

How can I specify the size of each of these dynamic_bytes, i.e. v [0], v [1], etc.? As in the general case, we determine the size through the constructor.

boost::dynamic_bitset<> x(3);
+5
source share
1 answer

This line

vector<boost::dynamic_bitset<>> v;

create an empty vector. Instead, you could request the filling of the default entries, all of which have the same value, so as usual

vector<int> v(N, 1);

to create a vector with Nall 1 entries that you could do

vector<boost::dynamic_bitset<>> v( N, boost::dynamic_bitset<>(3) ) ;

so that it contains N boost::dynamic_bitset<>with 3 bits.

If your vector contains enough elements, you should set v[i]to a different size

v[i] = boost::dynamic_bitset<>( 100 ) ;

, , - v.push_back(boost::dynamic_bitset<>(42)) .

+8

All Articles