I know that vector of bools is actually stored as bitsets. Wanted to understand why the implementation is like this? Why is implmentation not provided for normal bool type? What is the OS/Compiler level limitation?
Asked
Active
Viewed 39 times
0
-
A limitation isn't the reason for this. The reason is that it would be a lot of waste if you'd use 1024 bytes for 1024 bools if 128 bytes are enough to hold the information. – tkausl Jun 25 '16 at 07:23
-
6afaik this is not because of limitations but just an example where trying to be clever ended up in something not so nice – 463035818_is_not_an_ai Jun 25 '16 at 07:23
-
Thanks - I was intrigued because this optimization comes at a cost of vector
not behaving like an STL (From Effective STL). Was wondering if why would we do this optimization if we don't get desired features? – Ravi Jun 25 '16 at 07:29 -
Because it is in standard already. And removing it would be breaking backward compatibility. – Revolver_Ocelot Jun 25 '16 at 07:31
-
one could also consider it as a case where the c++ idea of "you dont pay for what you dont need" goes in the wrong direction, because everybody that expects a `vector
` to behave "as normal" has to pay for the decision they made – 463035818_is_not_an_ai Jun 25 '16 at 07:31 -
The standards committee [has discussed this since 1998](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#96) but not agreed on any of the proposed changes - except to possibly state that the specialization is deprecated. – Bo Persson Jun 25 '16 at 12:05