
From: "Noah" <noah@acm.org>
I hate having the shift value represent the flag - it's too easy to believe that you're just supposed to pass the value as is. Then you have to go lookup whether the value is a shift or the flag value itself. It's a serious pain.
I don't understand what you mean. I've never been confused when using left shift to generate the enumerator-definition.
You could have the best of both worlds if you wrap the parameter up in a class. Here's a brief sketch off the top of my head (so don't try to compile and use it!):
template<typename E> class BitFlag { int flag;
public: BitFlag(E val) { flag = 1 << val; } };
It makes the enum much easier to deal with since you can just simply put the flags in a list and not worry about explicitly initializing each flag. You can also add additional functionality. You could overload operators to handle passing or masking multiple flags. You could also, through the use of a traits class, validate flag combinations.
However wonderful that could be, the fact is that an enumerator-definition must be a constant-expression. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;