Visual C++ Developer Center >
Visual C++ Forums
>
Visual C++ Language
>
Are dynamic bitsets not supported?
Are dynamic bitsets not supported?
I was trying to use C++ STL bitsets in my code. But I felt that STL doesn't support dynamic bitsets. What I mean to say is that bitsets need to be initialised with a intial maximum number of bits, unlike vectors which grow at runtime.
bitset<6> b; // bitset implementation
I wan't to do something like this:
bitset* b;
b = new bitset(n); // where n represents the number of bits in the bitset b.
And here, the value of n is obviously runtime and not a constant. I could find neither an example nor any specification on this.
Is this functionality already present in STL bitsets or do I have to implement my own bitset which could provide this?
And vector<bool> is not an option for me because I want to use the bit logical operations provided by <bitset>
Please let me have your inputs on this.
Thanks.
Elroy D.
Answers
- I don't think that would be possible. Templates are expanded at compile time, so there is no way for you to specify the value at runtime. You could try implementing your own operators on the vector<bool> class.
- Marked As Answer byCode_Breaker Monday, September 01, 2008 8:36 AM
- Indeed. The STL bitset size is fixed at compile time by the template parameter. You'd need to implement your own dynamic version.
- Marked As Answer byCode_Breaker Monday, September 01, 2008 8:36 AM
- STL doesn't have dynamic bitsets but boost does: http://www.boost.org/doc/libs/1_36_0/libs/dynamic_bitset/dynamic_bitset.html
- Marked As Answer byCode_Breaker Monday, September 01, 2008 8:36 AM
All Replies
- I don't think that would be possible. Templates are expanded at compile time, so there is no way for you to specify the value at runtime. You could try implementing your own operators on the vector<bool> class.
- Marked As Answer byCode_Breaker Monday, September 01, 2008 8:36 AM
- Indeed. The STL bitset size is fixed at compile time by the template parameter. You'd need to implement your own dynamic version.
- Marked As Answer byCode_Breaker Monday, September 01, 2008 8:36 AM
- STL doesn't have dynamic bitsets but boost does: http://www.boost.org/doc/libs/1_36_0/libs/dynamic_bitset/dynamic_bitset.html
- Marked As Answer byCode_Breaker Monday, September 01, 2008 8:36 AM
- Thanks a lot guys for the inputs. But, I really feel STL should have supported it.
Elroy D.


