Reputation: 7980
I have a function that creates a std::bitset
, whose length is a constant function parameter. It doesn't work because the constant isn't an "integral constant expression". Is there any way I can make this work?
For reference:
void Foo(const std::string &data, const unsigned int size) {
std::bitset<size> Bar(data);
// Do something
return;
}
Upvotes: 1
Views: 133
Reputation: 533
The size of a std::bitset
needs to be evaulable at compile time. You can either make it big enough (in case you know the maximum size that you may need) or use another alternative, like boost::dynamic_bitset
as Igor Tandetnik suggested.
Upvotes: 2