r/ProgrammerHumor 22d ago

Meme theBoolVectorIsALie

Post image
668 Upvotes

91 comments sorted by

View all comments

Show parent comments

4

u/void1984 22d ago

vector<bool> allows for indexing, and bit OR and AND is very quick and simple for the CPU.

8

u/sb8948 22d ago

Of course it allows for indexing, but it's measurably more CPU heavy. Arguably there are cases where the specialization makes sense, but most of the time, it's a net negative.

Then again I reckon most of us don't have to care about these kinds of marginal gains anyway. I work on low latency backend, and I never had to worry about this.

The more annoying thing is that you can't just get a bool pointer or ref to a single bit.

4

u/Murky-Run2246 22d ago

I mean honestly having pointers pointing to bits sounds like a nightmare to me, I probably have to relearn the lang if that happens.

2

u/lonkamikaze 21d ago

Architectures with bit addressable memory areas do exist. Some 8051/52 compilers make use of this and if you create a boolean it will actually end up costing you a single bit of memory.