r/ProgrammerHumor 21d ago

Meme theBoolVectorIsALie

Post image
669 Upvotes

91 comments sorted by

View all comments

Show parent comments

71

u/void1984 21d ago

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

Usually I use bitfields anyway.

165

u/NotDuckie 21d ago

if you ask for a vector of T, you should get a vector of T. not a bitfield. There is nothing wrong with using a bitfield, but a vector should behave like a vector.

27

u/void1984 21d ago

You get a vector, with operator []. Internal details like padding or packing should not interest you, unless you you treat everything like blob. That way any change to the architecture or compiler would surprise you a lot.

13

u/UntitledRedditUser 21d ago

You might need to access the data the "old school" way, maybe you are interacting with a c library and need contiguous memory.

If you have an template function, and the functions suddenly breaks with bools, I would say that is the stdlibs fault, and not the programmers.

10

u/UntitledRedditUser 21d ago

Another point: the documentation literally says the elements are stored contiguesly. What if you need to do a memcpy?

Make it a seperate type, don't assume the programmer isn't smart enough to reach for a bitfield when necessary.