As a classic bit operation utility in C++,
std::bitsethas always been recommended for bit storage representation.
Although it lacks
begin()/end()member, its interface still looks like a container to me. I'm curious if there has been a proposal to turn it into a C++20range? [...] Is this an enhancement worth considering, or is it a bad idea?
std::bitsetis one of those “not quite really STL” types, likestd::stringandstd::valarray, that tries to fit a couple of use-cases but none of them are “STL iterable container.” Arguably, the hint is in its name: whereasvector<bool>is clearly a vector, a sequence container, of boolean values,bitsetis a set, a collection of small integer indices.bs.test(42)is the equivalent ofs.find(42);bs.set(42)is the equivalent ofs.insert(42); and so on. (As usual, these named methods throwstd::out_of_rangeon error, andbitsetprovidesoperator[]for faster unchecked access.)
If you were going to iterate over the “contents” of such an object, what would you expect to see?std::bitset<1000> bs;bs.set(42);for (auto elt : bs) {std::cout << bs;}Surely you wouldn’t expect to see “false, false, false, false, …”!