What's worse is that the spec says that all vector<T> must return a T& if you do an operator[] on them, but of course vector<bool> can't do this because there are no bools to reference, so the solution they came up with was to say that operator[] on vector<bool> returns a vector<bool>::reference which is an internal class that implicitly decays to bool.
This means that you can do `my_vec[0] = true;`, and you can do `bool b = my_vec[0];`, but if you do `auto b = my_vec[0];` then things go horribly wrong because the type of `b` is not `bool` but instead becomes `vector<bool>::reference`.
View all comments
Show parent comment
84
u/Semper_5olus 10d ago
Oh. So a bool is, for whatever reason, a different size if it's in a vector.
And that makes generic functions hard to write without checking for this specific case.
I didn't know that.
That is annoying.