标准是否保证std::less<MyEnumType>
将订购MyEnumType
就好像一个值MyEnumType
被转换为适当大小的整数类型?
enum MyEnumType { E1 = 0, E2 = 6, E3 = 3 };
Yes, std::less::operator()
定义为(§20.8.5/5):
operator()
回报x < y
对于在枚举类型上使用关系运算符,有以下规定 (§5.9/2):
通常的算术转换是对算术或枚举类型的操作数执行的。
对于无范围枚举类型,常见的算术转换被定义为进行积分推广。无作用域枚举类型的整体提升定义为 (§5/9):
A prvalue of an unscoped enumeration type whose underlying type is not fixed (7.2) can be converted to a prvalue of the first of the following types that can represent all the values of the enumeration (i.e., the values in the range bmin to bmax as described in 7.2): int
, unsigned int
, long int
, unsigned long int
, long long int
, or unsigned long long int
.
如果可用且需要,将使用扩展整数类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)