From d107a1876ee33b17f622d713a82346d611e9c554 Mon Sep 17 00:00:00 2001 From: neargye Date: Tue, 23 Jun 2020 16:31:28 +0500 Subject: [PATCH] wip --- include/type_safe/flag_set.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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