Is there any reason that std::bitset is implemented by template? Is this a good pattern that we should apply in some situations?
Because std::bitset
is designed to be a static bitset. In some cases, the compile-time size, will be very helpful, especially to the compiler, to optimize your program. If you want a dynamic bitset you can use boost::dynamic_bitset
. Just like there is std::array
and std::vector
, there's always a place for statically sized containers and dynamically sized containers.