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
{{ message }}
Repository navigation
Add find_prev() and find_last() and their _off to boost::dynamic_bitset #109
Currently, boost::dynamic_bitset provides find_first() and find_next() to efficiently iterate over set bits (1) in ascending order, as well as find_first_off() and find_next_off() for unset bits (0).
However, there are no equivalent methods for searching bits in reverse order.
I would like to propose adding four methods:
find_last(): Returns the index of the last (highest) set bit.
find_prev(pos): Returns the index of the previous set bit strictly before pos.
find_last_off(): Returns the index of the last (highest) unset bit.
find_prev_off(pos): Returns the index of the previous unset bit strictly before pos.
All methods should return npos when no matching bit exists.
These methods would provide a symmetric API with the existing find_first(), find_next(), find_first_off(), and find_next_off() methods, allowing efficient traversal of both set and unset bits in either direction.
Although reverse searches can be implemented manually, having native implementations would allow Boost to optimize them at the block level, avoiding bit-by-bit scanning or unnecessary temporary bitset allocations.
This would be particularly useful for algorithms that frequently need to find the highest set or unset bit, or iterate over bits in descending order.
changed the title [-]Add find_prev() and find_last() to boost::dynamic_bitset[/-][+]Add find_prev() and find_last() and their _off to boost::dynamic_bitset[/+]on Nov 17, 2026
I implemented find_prev() and find_last() (with slightly different names) in PR #103, upon another user's request. But, then, the user disappeared, so I didn't merge it (he was the only one to request them). I'll reconsider the request (and add the _off variants). Thanks.
Activity
[-]Add find_prev() and find_last() to boost::dynamic_bitset[/-][+]Add find_prev() and find_last() and their _off to boost::dynamic_bitset[/+]gennaroprota commentedon Nov 17, 2026
I implemented
find_prev()andfind_last()(with slightly different names) in PR #103, upon another user's request. But, then, the user disappeared, so I didn't merge it (he was the only one to request them). I'll reconsider the request (and add the_offvariants). Thanks.