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