I have a function to increment a bitstring as follows:
void increment(boost::dynamic_bitset<> &bitset)
{
for (int loop = 0; loop < bitset.size(); ++loop)
{
if ((bitset[loop] ^= 0x1) == 0x1)
{
break;
}
}
}
I want a function that is called in the same fashion as increment would be called, but modifies the bitstring differently. Every time it is called, I want to get the next bitstring with the same number of 0s as the previous one.
For example, if the bitstring is of length 10, the first 10 calls to this function will give a bitstring with a single 0. Then, calls 11 to 20 will return bitstrings with 2 0s. I want this to continue all the way down until the bitstring is all 0s.
How could I set up such a function? Thanks!