enum class FutureState {
ASYNC = 0x01,
DEFERRED = 0x02,
};
inline FutureState operator&(FutureState el, FutureState er)
{
return static_cast<FutureState>(static_cast<int>(el) & static_cast<int>(er));
}
inline FutureState operator|(FutureState el, FutureState er)
{
return static_cast<FutureState>(static_cast<int>(el) | static_cast<int>(er));
}
inline FutureState operator^(FutureState el, FutureState er)
{
return static_cast<FutureState>(static_cast<int>(el) ^ static_cast<int>(er));
}
inline FutureState operator~(FutureState el)
{
return static_cast<FutureState>(~static_cast<int>(el));
}
inline FutureState& operator&=(FutureState& el, FutureState er)
{
return el = el & er;
}
inline FutureState& operator|=(FutureState& el, FutureState er)
{
return el = el | er;
}
inline FutureState& operator^=(FutureState& el, FutureState er)
{
return el = el ^ er;
}
int main(int argc, char **argv)
{
FutureState state1 = FutureState::ASYNC & FutureState::DEFERRED;
FutureState state2 = FutureState::ASYNC | FutureState::DEFERRED;
FutureState state3 = ~state1;
FutureState state4 = state1 ^ state2;
state3 &= state1;
state4 |= state2;
state4 ^= state2;
return 0;
}
C++ enum class实现& | ^ ~等操作
最新推荐文章于 2024-09-04 10:57:59 发布