diff --git a/include/type_safe/flag_set.hpp b/include/type_safe/flag_set.hpp index 500ba7da..b1247cf0 100644 --- a/include/type_safe/flag_set.hpp +++ b/include/type_safe/flag_set.hpp @@ -559,6 +559,17 @@ class flag_set return flags_.to_int(); } + template + constexpr void for_each(UnaryFunction f) { + auto m = flags_.to_int(); + using U = decltype(m); + for (U i = 0; i < std::numeric_limits::digits; ++i) { + if ((m & (U{1} << i)) != U{0}) { + f(static_cast(i)); + } + } + } + //=== bitwise operations ===// /// \returns A set with all the flags flipped. constexpr flag_set operator~() const noexcept