type_safe icon indicating copy to clipboard operation
type_safe copied to clipboard

flag_set iterator(s) and/or for_each(flag_set<E>, [](E){})

Open ehoeks opened this issue 5 years ago • 2 comments

As many programmers I sometimes need to do some work for all flags set in an flag_set.

Can we add an type_safe way to iterate over all 'set' flags in an flag_set? e.g.

enum class my_enum; // some flag_set compatible enum class

void do_something_with(my_enum e);

{
  type_safe::flag_set<my_enum> some_flag_set();

  type_safe::for_each(
    some_flag_set,
    [](f){ do_something_with(f); }
  );
}

ehoeks avatar May 23 '19 09:05 ehoeks

If you be willing to write something, I'm happy for a PR.

foonathan avatar Jun 13 '19 07:06 foonathan

In case someone works on this, I think range syntax would also be nice:

  for (auto f : some_flag_set) {
    do_something_with(f);
  }

NikolausDemmel avatar Jun 16 '19 18:06 NikolausDemmel