With dynamic_bitset it is possible to initialise based on an integer value (5, 124 below). Are updates with integer values also possible?
The solution below allocates heap memory on every update when creating a new dynamic_bitset. This is a poor solution (slow, possible heap fragmentation etc.).
std::vector<boost::dynamic_bitset<uint8_t>> data;
data.push_back(boost::dynamic_bitset<uint8_t>(4, 5));
data.push_back(boost::dynamic_bitset<uint8_t>(7, 124));
for(const auto& s: data)
std::cout << s << std::endl;
for(int i; i<10; i++)
{
data[0]=boost::dynamic_bitset<uint8_t>(4, i);
for(const auto& s: data)
std::cout << s << std::endl;
}
Any ideas on how to update the value from an int without setting each individual bit?
Perhaps you can init from a block list:
However, since it seems to assert that the bitset be clear before init, it would feel more natural to use
append()
with the same effect (and possible more benefits when you need > 8 bits eventually):Live On Coliru
Prints