#includeusing namespace sdsl; int main(){ bit_vector b = {1,0,0,1,0,1,1,0,1,0}; bit_vector::select_1_type bs(&b); // create select1 index size_t pos = bs(0); // first set bit while(pos < b.size()){ std::cout << pos << "\n"; pos = bs(bs.rank(pos)+1); // next set bit } return 0; }
#includeThis code uses the `find_first` and `find_next` methods in the boost library to find the position of each set bit in a dynamic bit set. Package Library: - Example 1 uses the SDSL (Succinct Data Structure Library) package. - Example 2 uses the Boost C++ Libraries package.using namespace boost; int main(){ dynamic_bitset<> db(10); db.set(3); db.set(7); size_t pos = db.find_first(); while(pos != dynamic_bitset<>::npos){ std::cout << pos << "\n"; pos = db.find_next(pos); } return 0; }