开发者

Dynamic bit vector in C/C++

开发者 https://www.devze.com 2023-03-10 05:10 出处:网络
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 pro开发者_StackOv

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 pro开发者_StackOverflow中文版mising but it is templated so I cannot set the length of the bit vector dynamically. Can anyone advise? Thanks!


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:

http://hostilefork.com/nstate/


I have never used vector<bool> (See Scott Meyers' Effective STL item 18) but it might be just what you are looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消