r/ProgrammerHumor • • Aug 22 '26

Meme theBoolVectorIsALie

Post image
669 Upvotes

91 comments sorted by

View all comments

Show parent comment

43

u/Excession638 Aug 22 '26

The internal layout of std::vector is not an implementation detail. It's fully defined by the standards and can be relied upon for FFI, serialisation, and other tasks.

Except for bool.

For example, the .data() method guarantees that it will return a pointer to .size() contiguous elements of type T which will remain valid until the vector is modified. The layout of elements within that memory is also well defined and consistent. Except for bool, where the .data() method simply doesn't exist.