Is the <bool> vector a violation of the requirements of the container?
The standard C ++ draft n3242 in 23.2, in the table containing the requirements for the container, says that X::reference for the container containing T should be lvalue T However, for vector<bool> , vector<bool>::reference is another class, a proxy for accessing individual bits of bytes stored in a vector.
Does this mean that the std::vector class template specification for T = bool , defined in the standard, does not meet the requirements of the container?
Yes, vector<bool> does not meet the requirements of the container. He does not claim to be, although there are fairly obvious consequences. The fact is that the “requirements” of the container are not requirements in any formal sense; there is nothing in the standard library that requires a type that matches the requirements of the container. Rather, the "requirements" are descriptive: each container documentation can say (like the documentation for vector<bool> ), "this container meets the requirements of the container, with the exception of ...".
Yes Yes. Firstly, it uses the vector <bool>::reference proxy object, which is not really a link, but only looks the same (its class). Secondly, it has a flip () method, which other vectors do not have. In addition, it does not support conversion to a C-like array, unlike all other vectors: &vec[0] .
So, in fact, vector <bool> is not a vector, but looks like a vector, and its data is not bool , but it looks like bool . This container is considered “standardized but unsuccessful” worldwide.