If you are setting or reading a single bit, it is usually less performant because it requires more operations.
Also it can no longer be pointer iterated the same as any other vector could be, breaking templating code. You have to keep making special case code just for it.
And thats if you even know about it, since it's not clear just looking at the type that its completely different from every other specialization of its template.
Bitwise logic operations are supposed to be the fastest operations a CPU can run, though. Ideally you want to group up bits you're likely to read together into the same word so a single instruction reads all of them. Same goes for setting bits using a bitmask. You can still pointer iterate, but you're doing it per-word rather than per-bool. You'd get a speedup equal to the word size because you're effectively parallelizing your writes with a single bitwise logic instruction.
I personally tend to use C more than C++, and HDLs even more than that, but my first impression of bool was that it was meant to be a single bit in size so you could do things like that.
This seems like a special case that would benefit from its own type like bitset rather than having vectors arbitrarily work differently for a single type and break stuff unless you know to take care of it.
View all comments
Show parent comment
8
u/royavidan 14d ago
But if that's what you want, why not just use
std::bitset? Why does it have to be the default boolean vector type when it's worse most of the time?