On Thu, 08 Sep 2011 08:20:46 -0400, Timon Gehr <[email protected]> wrote:
On 09/08/2011 01:13 PM, Steven Schveighoffer wrote:
And in response to the discussion about enum flags not being & or |
together, I emphatically think enums should be used for bitfields.
Remember, enum is not just an enumeration, it's a manifest constant.
enum Enumeration{
field0,
field1,
}
enum manifestConstant=0;
There are other forms too:
enum MyConstants
{
const1 = 5;
const2 = 42;
}
enum flags {
flag1 = 0x01,
flag2 = 0x02,
flag3 = 0x04,
}
Those are clearly manifest constants with a namespace. The last one is a
bitfield.
I see no reason that we should not use the namespace-creation ability of
enum to create such constants. I don't see the downside.
The downside is that eg. final switch incorrectly assumes that enum
values are not composeable. It is imho a small inconsistency in the
language's design.
So don't use final switch? Again, not all enums are enumerations, you
have to judge whether final switch is applicable based on interpretation
of that.
-Steve