You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! Could we have a find_prev() to go along the find_next()? That would allow efficient reverse iteration over all 1-bits. The code should be pretty much the reverse of find_next(), and using countl_zero instead of countr_zero as the bit intrinsic function.
Apparently, some people are confused by the name of find_first_off() (they mix it up with find_first_of(), although the latter wouldn't make much sense for a bitset), so I'm thinking of the following renames:
find_first() → find_first_one()
find_first_off() → find_first_zero()
find_next() → find_next_one()
find_next_off() → find_next_zero()
Once I have decided on that, I'll implement the member you suggested. It will likely be named find_previous_one().
@rhalbersma: I sketched an implementation in PR #103. It adds a find_last_one(), too, although that's logically unnecessary, because a b.find_previous_one( i ) with i >= b.size() (e.g. i == npos) would find the last 1 bit. Please let me know what you think.
Activity
gennaroprota commentedon Jan 5, 2026
Hi Rein! Thanks for the suggestion :-).
Apparently, some people are confused by the name of
find_first_off()(they mix it up withfind_first_of(), although the latter wouldn't make much sense for a bitset), so I'm thinking of the following renames:find_first()→find_first_one()find_first_off()→find_first_zero()find_next()→find_next_one()find_next_off()→find_next_zero()Once I have decided on that, I'll implement the member you suggested. It will likely be named
find_previous_one().gennaroprota commentedon Jan 9, 2026
@rhalbersma: I sketched an implementation in PR #103. It adds a
find_last_one(), too, although that's logically unnecessary, because ab.find_previous_one( i )withi >= b.size()(e.g.i == npos) would find the last 1 bit. Please let me know what you think.gennaroprota commentedon Apr 28, 2026
This has been open for a long time without feedback. Going to close it.