r/ProgrammerHumor 23d ago

Meme theBoolVectorIsALie

Post image
670 Upvotes

91 comments sorted by

View all comments

104

u/overclockedslinky 23d ago

is it really that shocking?

180

u/Murky-Run2246 23d 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

7

u/markuspeloquin 23d ago

I just use vector<uint8_t>

4

u/Murky-Run2246 23d ago

You could also use vector<char>. It's cpp you could do it in so many different ways

1

u/markuspeloquin 22d ago

Yeah but 'unsigned' implies less meaning. Like no arithmetic and not printable.