Is there a way to find out size of a std::bitset
?
I have
typedef std::bitset<64> Bitset;
and I want to know the size without creating an instance. Eg. like Bitset::size
When I look to the sources in bitset.h
it is totally unreadable to me, but even though I found these lines
public:
enum {_EEN_BITS = _Bits};
typedef _Bitset_base<_Bits <= 8 ? 1
: _Bits <= 16 ? 2
: _Bits <= 32 ? 4
: 8> _Mybase;
typedef typename // sic
_Mybase::_Ty _Ty;
which I thought tell me, that _Ty
can contain size, but when I try to call Bitset::_Ty
i get illegal use of this type as an expression
I know I can store the size somewhere before I typedef the bitset but that is not what I want.
The default size of the bit set is 64-bit space. If the bit is set at index larger than the current BitSet size, it increases its bit space in the multiplication of 64*n, where n starts from 1, 2, 3, so on.
template< std::size_t N > class bitset; The class template bitset represents a fixed-size sequence of N bits. Bitsets can be manipulated by standard logic operators and converted to and from strings and integers.
Use Bitset::digits
instead, which corresponds to 64 in your case.
EDIT: As that turned out wrong, here's a different solution:
template< typename T >
struct GetSize;
template< size_t Len >
struct GetSize< std::bitset< Len > >
{
enum { Length = Len };
};
Used such as:
const size_t bitsetLength = GetSize< std::bitset< 1024 > >::Length;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With