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

Add: Extend DECLARE_ENUM_AS_BIT_SET with extra operations #8254

Closed
wants to merge 1 commit into from

Conversation

@techgeeknz
Copy link
Contributor

@techgeeknz techgeeknz commented Jul 2, 2020

The idea here is to simplify, and lower the cognitive overhead of, the common operations of setting, clearing, and interrogating bits of the various enums that are used as bitsets within the codebase.

For example:

  • setting bits: flags |= bits ==> flags += bits
  • clearing bits: flags &= ~bits ==> flags -= bits
  • mask testing: flags & mask != 0 ==> any(flags, mask), flags & mask == 0 ==> none(flags, mask)
  • membership: flags & mask == mask ==> all(flags, mask), flags & bit != 0 ==> test(flags, bit)

I originally tried <= and >= as subset and superset operators (respectively), but that seems to interfere with the builtin operators and break stuff; and I don't think we have any actual use cases for them anyway.

@techgeeknz techgeeknz force-pushed the techgeeknz:master_enum_bitsets branch 4 times, most recently from 0698973 to 4c6ef30 Jul 2, 2020
The idea here is to simplify, and lower the cognitive overhead of,
the common operations of setting, clearing, and interrogating bits
of the various enums that are used as bitsets within the codebase.
@techgeeknz techgeeknz force-pushed the techgeeknz:master_enum_bitsets branch from 4c6ef30 to e100e1f Jul 2, 2020
@LordAro
Copy link
Member

@LordAro LordAro commented Jul 2, 2020

We don't like adding code that serves no purpose. Functions should be added as and when they're needed, and adding 8 functions for every single bitset enum type isn't exactly going to help with optimisation/compile times/etc

@techgeeknz
Copy link
Contributor Author

@techgeeknz techgeeknz commented Jul 2, 2020

We don't like adding code that serves no purpose. Functions should be added as and when they're needed, and adding 8 functions for every single bitset enum type isn't exactly going to help with optimisation/compile times/etc

That's cool. I thought it'd be worth floating the idea to see if it had any merit. These are things we use a lot, so it's probably worthwhile to make their operations as readable as possible.

Obviously, this PR is incomplete and the purpose of this commit is to test the waters before diving in and rewriting every single bitset operation in the codebase.

@techgeeknz techgeeknz closed this Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.