2

Is there an efficient way to test subranges in std::bitset? This seems to suggest not.

I see std::bitset::any and std::bitset:all (for C++11), but they are for the whole set, not a subrange. What I was hoping for was an overloaded version of any and all. Something like:

bool all(size_t off, size_t len) const;

std::bitset::test is also just a single bit. Theoretically, I could construct bitsets to bit twiddle against, but these bitsets will be fairly large and this might not be reasonable.

Thoughts?

Thanks!

Community
  • 1
  • 1
Tim
  • 2,708
  • 1
  • 18
  • 32

1 Answers1

0

It is (at least theoretically) possible that your Standard Library has versions of the std::all_of, std::any_of and std::none_of algorithms specialized on std::bitset::iterator that make use of the Library's knowledge of the internals to provide more efficient implementations than you can yourself.

If not, it may be well worth your effort to write and contribute such specializations. Assuming, of course, that your standard library accepts such contributions on terms you're willing to agree to.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
  • `bitset` doesn't have iterators. – T.C. Oct 12 '16 at 21:41
  • Ah, good point. That's then one of the significant differences between `std::bitset`, `std::array` and `std::vector`. And this answer doesn't really contribute anything. If there's sufficient use cases, it may well be something to propose as an enhancement request for the Standard Library, then. – Toby Speight Oct 13 '16 at 08:10