On 25/06/2018 06:43, Julien Vernay wrote:
I think there are some issues with this kind of flagset : - you need to think about power-of-twos when attributing values to your flags. - you need to use bitwise operations which can be non-trivial, even for removing only one flag. - it is not safe: for example with another flagset using the flag INIT_VIDEO (in a window library like SDL), you can do " UP | INIT_VIDEO " even if the two flagsets have nothing in common
Note that C++11's scoped enums solve those safety issues. And if you don't care about the specific bit values (eg. you don't need to directly serialize the value or interoperate with an external API), then you can use bitfields, which resolve all of those issues (albeit with other limitations). Does your approach allow you to predefine standard combinations of flags (eg. defining UP_LEFT = UP | LEFT)? That's a common requirement for these sorts of things.