本文介绍了std ::更少的枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准是否保证std::less<MyEnumType>将对MyEnumType进行排序,就像将MyEnumType的值强制转换为适当大小的整数类型一样?

Does the standard guarantee that std::less<MyEnumType> will order MyEnumType as if a value of MyEnumType was cast to an appropriately sized integer type?

enum MyEnumType { E1 = 0, E2 = 6, E3 = 3 };

推荐答案

是的,std::less::operator()被定义为(§20.8.5/5):

Yes, std::less::operator() is defined as (§20.8.5/5):

对于在枚举类型上使用关系运算符,声明如下(第5.9/2节):

For using relational operators on enumeration types, the following is stated (§5.9/2):

对于无范围的枚举类型,通常的算术转换被定义为进行积分提升.无作用域枚举类型的整体提升定义为(§5/9):

For unscoped enumeration types, the usual arithmetic conversions are defined as doing integral promotion. Integral promotion for unscoped enumeration types is defined as (§5/9):

如果有需要,将使用扩展的整数类型.

An extended integer type will be used if available and required.

这篇关于std ::更少的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 20:48