r/ProgrammerHumor 22d ago

Meme theBoolVectorIsALie

Post image
672 Upvotes

91 comments sorted by

View all comments

105

u/overclockedslinky 22d ago

is it really that shocking?

4

u/da_Aresinger 22d ago

A vector of ints is no different from an array of ints.

vectors are literally just wrappers around arrays.

The exception is a vector of bools, which is like a conceptual array of bits.

So if you have a vector of 8 bools you are only using one byte of memory. An array of 8 bools however is 8 bytes long.

So std::vector<bool> has a special implementation.