std::ios_base::fmtflags? It's pretty much an established C++
idiom, in the cases where you need such bitmasks---typically,
they're most frequent in low level code, and application level
code won't use them at all.
And setting an enum variable to a value not defined in that
enum doesn't?
Not as the C++ type system is defined. The definition of enum
type is very carefully crafted to support this.
I must admit to a strong bias against setting an enum variable
to a value not defined in that enum which originated in a C
project long ago.
One programmer was doing this as then passing the results to
functions with the enum type as a parameter. A good number of those
used the value in a switch statements and he tended to omit the default.
I spent weeks tracking them all down. So you could say I suffer form
post enum abuse stress!
And how would using int instead have helped here. The question
is one of semantics, independent of the type.
As I said, the enum type in C++ is designed to fulfill two very
distinct roles. Arguably, there should be two different types,
but for various historic reasons, there aren't. In well written
code, it should always be very clear which role is being used
(although there are some special cases where the roles are a bit
mixed, e.g. std::ios_base::floatfield); if for any reason, it is
not clear, the code should clearly document it. If the enum is
used as an enumerated type, of course, you definitely shouldn't
overload operator| et al., and you shouldn't assign a value not
in the enum declaration to the enum. If the enumerated type
being used for bitfields, on the other hand, you should never
write a switch on it.