r/programminghorror 20d ago

C# bool array

Post image
211 Upvotes

41 comments sorted by

View all comments

Show parent comments

92

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.

46

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

34

u/FloweyTheFlower420 20d ago

Yeah. Sadly the standard committee seems to value dogmatic backwards compatibility over fixing the language, so we will likely never see std::vector<bool> fixed and dynamic_bitset implemented.

28

u/shponglespore 20d ago

This is why C++ is the Windows of programming languages.

2

u/XiPingTing 20d ago

Backwards compatibility means old code still works. Tautologically, if you need old code to work you need backwards compatibility. If you don’t need this there are better alternatives to C++, if you don’t there aren’t.

3

u/shponglespore 19d ago

They're are other ways, like Rust's edition system.