why scoped enum support operator < by default

  • A+
Category:Languages
enum class Number {one , two}; if (Number::one < Number::two) {} 

My understanding is that scoped enum needs to be cased into underlying type or integer then it can be applied to operator < > ==. But it looks code snippet above can work w/o any explicit overloadding operator <.

I don't see any descriptions in https://en.cppreference.com/w/cpp/language/enum

Anyone can point me how C++ standard says which operators are supported for scoped enum by default?

 


My understanding is that scoped enum needs to be cased into underlying type or integer then it can be applied to operator < > ==.

Not when both of them are scoped enums. SomeScopedEnum < SomeInt is ill-formed, you're right in that case.

[expr.rel]p6:

If both operands (after conversions) are of arithmetic or enumeration type, each of the operators shall yield true if the specified relationship is true and false if it is false.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: