Email or username:

Password:

Forgot your password?
Top-level
Gankra

ye who write c++, what is thine feelings about std::vector<bool>?

Anonymous poll

Poll

yes i c++, vector<bool> rules
15
6.2%
yes i c++, vector<bool> sucks
87
36%
i don't c++, vector<bool> rules
14
5.8%
i don't c++, vector<bool> sucks
62
25.6%
wait vector<bool> is special?
64
26.4%
242 people voted.
Voting ended 16 July at 16:40.
5 comments
Gankra

for those who don't know: it's standard (required?) for C++'s std::vector<bool> to be specialized to actually bitpack the booleans, getting you 8x the booleans per allocated byte (nice!)

...at the cost of any API that returns T* or the like now being literally impossible to satisfy, silently deleting random APIs from the std::vector interface (oh no!)

aiui this makes code that generically works with vectors now randomly incompatible with that particular substitution (unless you very carefully avoid those APIs)

for those who don't know: it's standard (required?) for C++'s std::vector<bool> to be specialized to actually bitpack the booleans, getting you 8x the booleans per allocated byte (nice!)

...at the cost of any API that returns T* or the like now being literally impossible to satisfy, silently deleting random APIs from the std::vector interface (oh no!)

Nicole

@Gankra I don't believe it's required to bitpack, but the APIs are required not to return a pointer so there's no reason not to.

Nicole

@Gankra fwiw, my opinion is "it's overhyped how terrible vector<bool> is, but it's certainly not good"

Gankra

@streganil i think that's where i fall too, yeah. vector<bool> is relatively rare, so it won't come up much, but it's unfortunate that a desire to optimize the concrete case of vector<bool> made the whole vector type just a little less useful in generic contexts

Ed Page

@Gankra @streganil

> a desire to optimize the concrete case

And it wasn't even created as an optimization but for pedagogical purposes.

> The vector<bool> specialization was intentionally put into the standard to provide an example of how to write a proxied container.

gotw.ca/publications/mill09.ht

Go Up