I understand that Bitsets can't be dynamically allocated because they are based on Template Parameters.But why were bitsets implemented that way?
Thanks
This is done to make sure bitsets have characteristics as close as possible to those of an unsidned integer (which is widely used to represent bitsets otherwise). One of them, responsible for the size being a template parameter is a requirement to have no implicit dynamic memory allocation.
For situations when dynamic size is more important than other characteristics one can use boost dynamic_bitset.
Efficiency? Because it's a common use-case? If you want a dynamic bit sets consider vector<bool>
. It even has some bit operations defined on it. But read this first.