Reputation: 9031
C++ standard draft n3242 in 23.2, in table containing container requirements, states that X::reference
for container containing T
must be lvalue T
. Yet, for vector<bool>
, vector<bool>::reference
is another class, a proxy for accessing individual bits of bytes stored in vector.
Does that mean that std::vector
class template specification for T = bool
, defined in standard, fails to fulfill container requirements?
Upvotes: 4
Views: 275
Reputation: 7357
Yes, it do. First, it uses proxy object vector <bool>::reference
which is not actually a reference, but only looks same(its a class). Second, it have flip() method that other vectors does not have. Also, it does not support converting to C-like array unlike all other vectors: &vec[0]
.
So, actually vector< bool> is not a vector but looks like vector and its data is not a bool but look like bool. This container is worldwide considered as "standardized but failed thing".
Upvotes: 1
Reputation: 76245
Yes, vector<bool>
does not meet the container requirements. It doesn't claim to, although there is a fairly clear implication. The thing is, the container "requirements" aren't requirements in any formal sense; there is nothing in the standard library that requires a type that meets the container requirements. Rather, the "requirements" are descriptive: each container's documentation can say (as does the documentation for vector<bool>
) "this container meets the container requirements, except ...".
Upvotes: 4
Reputation: 354979
Does that mean that
std::vector
class template specification forT = bool
, defined in standard, fails to fulfill container requirements?
Yes.
Similarly, its iterators are not truly random access iterators, because operator*
yields a proxy object.
vector<bool>
is a mess.
Upvotes: 10