I have a boost dynamic_bitset that I am trying to extract from bits:
boost::dynamic_bitset<unsigned long> myBitset(1000);
My first thought was to make a simple "dump" cycle through each index and ask if it was installed:
for(size_t index = 0 ; index < 1000 ; ++index) { if(myBitset.test(index)) { /* do something */ } }
But then I saw two interesting methods: find_first() and find_next() , which, as I thought, were intended for this purpose:
size_t index = myBitset.find_first(); while(index != boost::dynamic_bitset::npos) { /* do something */ index = myBitset.find_next(index); }
I have done some tests and it seems that the second method is more efficient, but it concerns me that there may be another βmore correctβ way to perform this iteration. I could not find in the documentation any examples or notes indicating the correct way to iterate over the given bits.
So, uses find_first() and find_next() best way to iterate over dynamic_bitset , or is there another way?
c ++ boost
Jaredc
source share