I tried and searched, and I think the best solution is a #define. Based on something I found:
#define FLAGS(T) \
inline T operator |(const T s, const T e) { return (T)((unsigned)s | e); } \
inline T &operator |=(T &s, const T e) { return s = s | e; } \
inline T operator &(const T s, const T e) { return (T)((unsigned)s & e); } \
inline T &operator &=(T &s, const T e) { return s = s & e; } \
inline T operator ^(const T s, const T e) { return (T)((unsigned)s ^ e); } \
inline T &operator ^=(T &s, const T e) { return s = s ^ e; } \
inline T operator ~(const T s) { return (T)~(unsigned)s; }
This can be used like:
enum some_state {
state_normal = 1 << 0,
state_special = 1 << 1,
state_somethingelse = 1 << 2,
state_none = 0,
};
FLAGS(some_state)
some_state var1;
For Visual Studio one might need this to silence some warnings:
#pragma warning(disable: 4505) // '*' : unreferenced local function has been removed