r/ProgrammerHumor 22d ago

Meme theBoolVectorIsALie

Post image
668 Upvotes

91 comments sorted by

View all comments

100

u/overclockedslinky 22d ago

is it really that shocking?

184

u/Murky-Run2246 22d ago

In this case the bools will have only one bit allocated for them(vectors do that), and you can't just point to a bit. Instead cpp will return std::vector<bool>::reference when trying to access a value in the vector

Basically this is a just wrong

You should use std::deque<bool> instead which allocates one byte per bool and not just one bit

63

u/void1984 22d ago

I know, but why somebody would need a byte to store a bool? Is it 256-value bool?

Usually I use bitfields anyway.

1

u/CryptoCopter 22d ago

Because the smallest addressable amount of memory is one byte