Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for_each flag_set #114

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/type_safe/flag_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,18 @@ class flag_set
return flags_.to_int();
}

template <typename UnaryFunction>
TYPE_SAFE_CONSTEXPR14 UnaryFunction for_each(UnaryFunction f) const {
using int_type = typename detail::flag_set_impl<Enum>::int_type;
int_type m = flags_.to_int();
for (int_type i = 0; i < std::numeric_limits<int_type>::digits; ++i) {
if ((m & int_type(int_type(1u) << i)) != int_type(0u)) {
f(static_cast<Enum>(i));
}
}
return f;
}

//=== bitwise operations ===//
/// \returns A set with all the flags flipped.
constexpr flag_set operator~() const noexcept
Expand Down