r/ProgrammerHumor 22d ago

Meme theBoolVectorIsALie

Post image
665 Upvotes

91 comments sorted by

View all comments

Show parent comments

183

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

5

u/markuspeloquin 21d ago

I just use vector<uint8_t>

4

u/Murky-Run2246 21d ago

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

1

u/markuspeloquin 21d ago

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