15

Today, virtually all C++ developers agree that std::vector<bool> was a mistake since it is deceivingly not a container, and its use cases largely overlap with those of std::bitset anyway.

How did it get voted into the standard? Was it controversial at the time? What were the main supporting arguments?

10

From Herb Sutter using the reference quoted:

The vector specialization was intentionally put into the standard to provide an example of how to write a proxied container. A "proxied container" is a container whose objects you don't get at directly; instead of giving you pointers or references to a contained object, a proxied container gives you proxy objects that can be used to indirectly access or manipulate a contained object. Proxied collections can be useful in cases where the objects within the collection cannot always be reliably accessed directly as though they were in memory, as for example with a disk-based collection that automatically pages pieces of itself in and out of memory under the covers as needed. So the idea was to show how to make such a proxied collection meet the requirements of a "container" in the sense defined by the standard library.

And yes, there was discussion at the time.

  1. For all the gory details, surf to DejaNews and do a power search for Subject="vector and bool" and Forum="c++". The discussions took place in Jan/Feb 1997. You will also find more recent discussions from people asking how to turn off the vector specialization; see the end of this article for my advice.

The rest is history. And I hate seeing an unanswered question with such good links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.