Creating vector of boost dynamic_bitset in C++
boost, c++
Solution
This line
vector<boost::dynamic_bitset<>> v;
create an empty vector. Instead you could have requested it be filled with default entries which all have the same value, so like one usually does
vector<int> v(N, 1);
to create a vector with `N` entries all 1 you could do
vector<boost::dynamic_bitset<>> v( N, boost::dynamic_bitset<>(3) ) ;
to have it contain `N` `boost::dynamic_bitset<>`s with 3 bits.
If your vector contains enough elements you should be able to set the `v[i]` to a different size
v[i] = boost::dynamic_bitset<>( 100 ) ;
Alternative you could create an empty vector like you currently do and just use something like `v.push_back(boost::dynamic_bitset<>(42))` to add correctly sized elements.
Problem
I want to create an array of dynamic_bitsets. So I created a vector of dynamic_bitset using, `vector<boost::dynamic_bitset<>> v;` How can I specify the size of each of these dynamic_bitsets i.e. v[0], v[1] etc? Like in a general case, we specify the size through the constructor. ``` boost::dynamic_bitset<> x(3); ```