Re: Comparing two vectors of bools
James Kanze wrote:
On Aug 2, 12:13 pm, "Bo Persson" <b...@gmb.dk> wrote:
Juha Nieminen wrote:
Rafal wrote:
fgh.vbn....@gmail.com wrote:
I know that std::vector<bool> is specialized to store individual
bools as single bits.
Actually this is considered a bit of "hack" and AFAIR it will be
removed soon (in C++0x?).
Exactly how is it a "hack" and why should it be removed? Has a
better alternative been suggested?
It's strange because it is the only container that does not
store elements of the contained type.
But it does. At least as far as client code can tell. And
bitset is in a similar situation. It's strange because it's
called std::vector<bool>, but it doesn't conform to the
documented contract of std::vector.
It also uses a proxy class for vector<bool>::reference, which
is not allowed by the standard for any other container.
Again: bitset.
Yes, I forgot about that one. :-)
It claims to be an associative container, but doesn't have the
required interface.
I should have written that the general container requirements (section
23.1) doesn't allow for this (reference as a proxy). On the other hand
it is still required in some places...
The problem isn't that it's there. The problem is that it is
called std::vector< bool >, and not something else. (Or
alternatively, the problem is that the contract for std::vector
is too constraining. You can argue it both ways. But if you
take this second approach, you're going to have to change some
of the basic principles of the STL.)
The contract is cracking up anyway, as the revisions for the next
standard introduces new containers and new requirements that just
don't go well together.
Just like bitset is (supposedly) an associative container with a fixed
size (and therefore has a non-conforming different interface), C++0x
introduces a std::array as a fixed size sequence container which
cannot implement insert and erase, for example. We also have
basic_string claiming to be a sequence container, but falling short.
In comparison, vector<bool> seems like a minor problem. .-)
Bo Persson