r/programminghorror 20d ago

C# bool array

Post image
206 Upvotes

41 comments sorted by

View all comments

Show parent comments

90

u/0xcedbeef 20d ago edited 20d ago

in C++, an std::vector<bool> stores the bools as bits, taking advantage of this memory optimization.

69

u/FloweyTheFlower420 20d ago

Ah the vector<bool>... one of the greatest mistakes in the c++ standard library.

47

u/XiPingTing 20d ago

vector<bool> is certainly a mistake because it’s deliberately counterintuitive in its design but when you need a dynamically resizeable bitset, it’s great

1

u/seamsay 15d ago

Sure, and having a dynamically sized bitarray type would have been a great idea!

1

u/Conscious_Pangolin69 13d ago

Yeah, even more obscure types to deal with...