I would like to use the std::bitset::all
but unfortunately my compiler is pre-dated C++11. I know that I could mimicate the functionality by checking in a loop whether all bits of my std::bitset
are set.
e.g.,
template<std::size_t N>
bool
all(std::bitset<N> const &bs) {
int hits(0), sz(bs.size());
for(int i(0); i < sz; ++i) {
hits += bs[i];
}
return hits == sz;
}
Q:
Is there a more proper implementation of a std::bitset::all
substitute for pre-dated C++11 compilers than the one displayed above.
Another way would be to use template metaprogramming and unroll the bits of the bitfield like the example below:
LIVE DEMO