Opened 8 years ago
Last modified 8 years ago
#11122 new Feature Requests
Bulk/Range set/unset operations
Reported by: | Owned by: | jsiek | |
---|---|---|---|
Milestone: | To Be Determined | Component: | dynamic_bitset |
Version: | Boost Development Trunk | Severity: | Problem |
Keywords: | Cc: |
Description
I need to set/unset a subrange of the elements within a dynamic bitset. The current best way (that I know of) of doing this, is assigning a value to each element individually.
This is far from optimal, since an optimal solution would iterate over the blocks, setting the value once for each block. It is also non-trivial to work around this, since one needs to consider that the sub-range might being and end in the middle of some block.
I propose to add the following two overloads to the set and unset member functions, to allow for this use case:
std::size_t set(std::size_t from, std::size_t to, bool value); std::size_t unset(std::size_t from, std::size_t to, bool value); (maybe range-based and iterator-based versions should be added as well)
I'm willing to implement, test, and document this. But want to discuss before:
What do you think? Is there a better solution to this problem that is both safe and efficient?
Sorry, I missed a last edit. Having set and unset overloads both taking a value parameter makes no sense at all.
I propose to add the following overload (just one) to the set member function to allow for this use case:
std::size_t set(std::size_t from, std::size_t to, bool value = true);
For interface symmetry one should consider set(from, to), reset(from, to), as well as iterator based, and range based versions, but I am not proposing these right now.