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.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
  .oOOOo.   o.     O                            o     
.O o Oo o O
o O O O o
O O o o o
O .oOOo O o O 'OoOo. 'o O `OoOo. O o
o. O o O O o O O o o o OoO
O. oO o Oo O o o O O O o O
`OooO' O `o o O `Oo'oO' o O o

Enter the code depicted in ASCII art style.