4

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?

4 Answers 4

10

Does that mean that std::vector class template specification for T = 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Not really a mess; it's handy, and it works. You do have to be careful in generic code that deals with vectors, though.
It would have been better not to have specialized vector, though, and instead to have defined an entirely new type. Hindsight is 20/20.
7

Yes, as stated here with a nice explanation.

1 Comment

Well, with a one-sided explanation. <g> He didn't win that battle.
4

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 ...".

Comments

1

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".

1 Comment

Um, no, it's not worldwide considered as failed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.