Public service announcement to all you young, naive C++ programmers out there like me! Your trusty
std::vector<...> is not always what it seems!
std::vector<bool> is a lie. Don't use it unless your C++-fu is great enough that you already knew what I was talking about before you began reading this post, in which case you already know enough not to use it.
I spent a couple hours this morning banging my head off my desk because of the apparently eradic and inexplicable behavior of this nonconformant container. Had I only noticed that
std::vector<bool> is actually its own specialization of
std::vector! It is a micro-optimized version of
std::vector which breaks some of the expected behavior. It throws away the continous memory guarantee. If you don't believe me, just ask Herb Sutter. See also Alternative to vector<bool> on StackOverflow.
std::vector<bool>! And I hope that, unlike me, you find out before banging your head off your desk.