I am looking for an off-the-shelf dynamic bit vector in C or C++ that I can use. Unfortunately for various reasons I cannot use the BoosT libraries at the moment. std:bitvector looks promising but it is templated so I cannot set the length of the bit vector dynamically. Can anyone advise? Thanks!
Asked
Active
Viewed 1,996 times
3
-
can't you use `vector
` as a base for your bitvector? – Ali1S232 Jun 04 '11 at 21:00 -
and you can use reserve as many data as you want or just call push_back – Ali1S232 Jun 04 '11 at 21:02
-
6What is it about Boost that disqualifies it? I ask because I want to make sure the *other* third-party classes people might recommend don't also suffer from the same things that prevent you from using Boost. – Rob Kennedy Jun 04 '11 at 21:03
-
Please see http://stackoverflow.com/q/551579. Also, please list your requirements in detail. Do you need to access the bits in packed form with a C pointer? If so, you can implement your own resizable bit container using `vector
` or `vector – rwong Jun 04 '11 at 21:05` together with some bitwise operations. -
also http://stackoverflow.com/q/670308 – rwong Jun 04 '11 at 21:11
2 Answers
2
You don't have to put a dependency onto all of boost and its installation process just to use dynamic_bitset
. If the class suits your purposes, copy the source files for it specifically into your project tree and put it in a separate namespace called "boostcopy" (or something like that).
On a similar note, I made my own resizable array class modeled after dynamic_bitset called "Nstate", which you can template to an arbitrary radix and still get tight packing. Perhaps of interest:

HostileFork says dont trust SE
- 32,904
- 11
- 98
- 167
2
I have never used vector<bool> (See Scott Meyers' Effective STL item 18) but it might be just what you are looking for.

dalle
- 18,057
- 5
- 57
- 81

IronMensan
- 6,761
- 1
- 26
- 35