-
Notifications
You must be signed in to change notification settings - Fork 41
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
Added FlagSet utility class #118
Conversation
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
This is a bit difficult to evaluate without more context, do you think you could open a draft PR showing the intended use? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One piece of API feedback in comments.
Does it also make sense to implement std::hash
the same way that bitset
does so that it is usable in things like unordered_map
and unordered_set
?
Do you have a use-case for indexing by bitsets? I can imagine indexing by enum values, but by whole bitsets? |
I was mainly thinking of parity with the Dispatching based on a certain configuration of flags, so maybe:
Or potentially keeping a set of valid configurations to check against:
|
@peci1 friendly ping |
I'll have a look at it over Xmas. This week's my vacation. |
@peci1 , do you need this to go into |
Oh I just saw that you're using it for the video encoder in #125 , so that answers my question. |
Yes, you're right, I'd like to use this PR in the hardware support for video encoder. But it could be possible to factor this out to a new package starting with Edifice. |
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz> Signed-off-by: Martin Pecka <peci1@seznam.cz>
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz> Signed-off-by: Martin Pecka <peci1@seznam.cz>
I did what was requested (renamed the static constructors and added support for std::hash). I got one more idea - now the class requires that the last element of the enum is an underscore. That is because of two things:
I think 1. can be overcome by exposing an explicit template argument for the number of elements in the enum. That would allow much broader use of FlagSet even with enums you do not control. You would just have to pass the correct number of elements. I know this can be difficult to maintain, but many projects use something other than underscore, e.g. It seems that it is not possible to overcome 2., so let's say only underscore-ending enums would get this syntactic sugar (ORing two base values creates the FlagSet containing both of them). But that's just syntactic sugar. What do you think about this? |
I don't think I mind having the underscore as the last entry in this case. That seems easier (maintenance-wise) than having to keep track of the number of elements. I do see the advantage of exposing the other alternative in the case that it is an enum that we do not maintain/control. I also agree that disabling the |
Friendly ping @peci1, is there anything else you want to do here? |
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz> Signed-off-by: Martin Pecka <peci1@seznam.cz>
I implemented the option for explicit specification of the last element (and whether to treat it as a valid member of the enum or not). I also added some more convenience methods like initializer-list constructor. I'm satisfied with this PR now (but feel free to comment on the new changes). |
This class helps managing a set of flags that are defined as a C++11 enum class.
Adapted from https://github.com/mrts/flag-set-cpp (MIT license, compatible with Apache 2.0).
I have a use for this class in my next PR (not yet published as it needs polishing). But I think it might be generally useful to have a canonical way to work with flag sets.