r/ProgrammerHumor • • 11d ago

Meme cppAndItsVectorBooleans

Post image
3.4k Upvotes

214 comments sorted by

View all comments

Show parent comment

10

u/_killer1869_ 10d ago

A bool, by definition, in just about any language there is, always takes up the amount of space of the lowest addressable memory unit, which is 8 Bit (excluding some special, outdated architectures where you can access single bits directly). C++ is the only language I know of where a data type using bool uses single bits for storing them. Is it more efficient? Yes. But it breaks the universally accepted standard. Consistency is far more important than minimal efficiency improvements. Just add a seperate data type for when you really need that efficiency into the standard library.

5

u/Still_Bit_7527 10d ago

It's even worse. C++ itself actually uses a whole byte for bools. It's only vector that uses bits to optimize when it's a vector of bools

-2

u/geekosas 10d ago

Standard created by Samsung and HK hynx?

Like when pharma diagnosed 50% of kids with ADHD.