Skip to main content

bitset vs vector

Posted in

It is a very popular question what are the differences between bitset and vector. Here they are (probably, these are the main differences, but not all of them, I guess)

bitset vector
Const size (once created) Yes No
Iterating through elements No Yes
Element search No Yes
Is container? No (bitset<T> makes no sense) Yes
Space allocation optimization? No Yes (see this.)

Looks like std::vector has knocked the bitset out.

implementation choice

You could find or make your own bitset implementation which isn't const-sized, allow iterating or element search, allow cycling or moving the bits, etc...

(but the reference class would still be almost the same as on the STL, it's a requirement because C/C++ doesn't allow direct bit management, only with mask and bit operation)

Won't I get something similar

Won't I get something similar to vector?

just a little, you could add

just a little, you could add features only usefull to bitset without having const-size once created, like the cycling or bit moving.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
_y_ophone: