Is there any way to do something like this in C++:
int a;
bitset<a>;
Is there any way to do something like this in C++:
int a;
bitset<a>;
No it's not possible, since std::bitset<>
expects a constant bitsize value, that can be resolved at compile time.
What you can do though is providing a const
value:
const int a = 42;
// ^^^^^
bitset<a>;
As mentioned in the other answer, there's not really a dynamically sized bitset provided from the current c++ standard (The std::vector<bool>
specialization has serious drawbacks regarding usage in standard algorithms).