Counting flags in a bit mask
Hi,
I am using a enum as a bit mask. I also use Q_DECLARE_FLAGS. Now I have the need to know how many flags are set, but I can't find a simple solution for that: will say no build in function. For now I use a simple loop which counts the flags. Just wondering if there is a "standard"/better way without a self defined function...
Thanks
QFlags::cont() would have been nice:cool:
Re: Counting flags in a bit mask
Flags don't have to be exclusive, so any count() wouldn't work.
Here you go for some algorithms: http://graphics.stanford.edu/~seande...ntBitsSetNaive