diff options
author | Bardur Arantsson <bardur@scientician.net> | 2016-06-20 22:49:05 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2016-06-20 22:49:05 +0200 |
commit | af3dd99eff4eeee5231a9e77f876126ef67ae664 (patch) | |
tree | 911a0c728436da64b59230c7454072c6df3c169c | |
parent | f66fbf3dc0a324fbf17e2148a025ea703c6b4d83 (diff) |
Add flag_set::count() method to count set bits
-rw-r--r-- | src/flag_set.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/flag_set.hpp b/src/flag_set.hpp index b4bdc92f..aa90a217 100644 --- a/src/flag_set.hpp +++ b/src/flag_set.hpp @@ -67,6 +67,19 @@ public: return true; } + constexpr std::size_t count() const + { + std::size_t n = 0; + for (std::size_t i = 0; i < nbits; i++) + { + if (bit(i)) + { + n += 1; + } + } + return n; + } + uint32_t &operator[](std::size_t i) { assert(i < tiers); |