May 2017
Intermediate to advanced
590 pages
17h 18m
English
The std::vector<bool> interface is very different from std::bitset. If you want to be able to write code in a similar manner, you can create a wrapper on std::vector<bool>, which looks like std::bitset, where possible. The following implementation provides members similar to what is available in std::bitset:
class bitvector { std::vector<bool> bv; public: bitvector(std::vector<bool> const & bv) : bv(bv) {} bool operator[](size_t const i) { return bv[i]; } inline bool any() const { for (auto b : bv) if (b) return true; return false; } inline bool all() const { for (auto b : bv) if (!b) return false; return true; } inline bool none() const { return !any(); } inline size_t count() const { return std::count(bv.cbegin(), bv.cend(), ...Read now
Unlock full access