In the documentation, I can see that std::vector<bool>
is optimized for space-efficiency by making every boolean occupy one single bit. From the documentation:
The manner in which std::vector is made space efficient (as well as whether it is optimized at all) is implementation defined.
Does this mean that it depends on the compiler's implementation? If it does, where can I check if my compiler supports it? Why wouldn't they want it supported? It seems like a really simple and efficient implementation.
If not, what does it mean and what does it imply if I want this optimization to take place?
I'm using TDM GCC toolset.
The formal language definition doesn't want to exclude reasonable implementations, so they always have to be a bit careful.
For instance, a typical debug build is still Standards-conforming, but I could very well see a vector<bool>
not being compressed in debug mode.
Now this is not unspecified but implementation defined. That means the fact whether it's compressed should be in the compilers documentation somewhere, but the Standard doesn't describe how the documentation should be organized.
If your compiler doesn't support it as you'd like, you can just use another library (Boost being the obvious candidate). vector<bool>
typically isn't a class that depends on deep compiler magic, so alternatives are easy to write.