Creating vector of boost dynamic_bitset in C++ -
i want create array of dynamic_bitsets. created vector of dynamic_bitset using,
vector<boost::dynamic_bitset<>> v;
how can specify size of each of these dynamic_bitsets i.e. v[0], v[1] etc? in general case, specify size through constructor.
boost::dynamic_bitset<> x(3);
this line
vector<boost::dynamic_bitset<>> v;
create empty vector. instead have requested filled default entries have same value, 1 does
vector<int> v(n, 1);
to create vector n
entries 1
vector<boost::dynamic_bitset<>> v( n, boost::dynamic_bitset<>(3) ) ;
to have contain n
boost::dynamic_bitset<>
s 3 bits.
if vector contains enough elements should able set v[i]
different size
v[i] = boost::dynamic_bitset<>( 100 ) ;
alternative create empty vector , use v.push_back(boost::dynamic_bitset<>(42))
add correctly sized elements.
Comments
Post a Comment