-5

Is there any way to do something like this in C++:

int a;
bitset<a>;
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

1 Answers1

2

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).

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190