Hellow my friends!
In MSVC2013 perfectly works for me this macro (which allow use enum class as flag enum and disallow convert to int):
#pragma once #define EnumClass(Enum, Type) \ enum class Enum : Type; \ inline Enum operator & (Enum x, Enum y) {return static_cast<Enum> (static_cast<Type>(x) & static_cast<Type>(y));}; \ inline Enum operator | (Enum x, Enum y) {return static_cast<Enum> (static_cast<Type>(x) | static_cast<Type>(y));}; \ inline Enum operator ^ (Enum x, Enum y) {return static_cast<Enum> (static_cast<Type>(x) ^ static_cast<Type>(y));}; \ inline Enum operator ~ (Enum x) {return static_cast<Enum> (~static_cast<Type>(x));}; \ inline Enum& operator &= (Enum& x, Enum y) {x = x & y; return x;}; \ inline Enum& operator |= (Enum& x, Enum y) {x = x | y; return x;}; \ inline Enum& operator ^= (Enum& x, Enum y) {x = x ^ y; return x;}; \ enum class Enum : Type
But in Intel C++ 14.0 fails on:
EnumClass(ToolhelpSnapshotFlag, unsigned __int32) { List = 0x00000001, Process = 0x00000002, Thread = 0x00000004, Module = 0x00000008, Module32 = 0x00000010, All = List | Process | Thread | Module, //error : expression must have a constant value Inherit = 0x80000000 };
How to enable works this on Intel C++ 14.0 without converting result of all operators to underlying type?