是否可以知道非固定枚举者的范围

Is it possible to know the range of an non-fixed enumerator?

本文关键字:枚举 范围 是否      更新时间:2023-10-16

有没有办法知道枚举的值范围?我期待像std::numeric_limits这样的type_traits模板,但我没有找到任何人。

例如:

enum enm { A = -5, B = 3 };
std::cout << std::range_of_enum<enm>::min() << ', '
          << std::range_of_enum<enm>::max() << std::endl;
// Prints -8, 7 with two's complement representation, and -7, 7 
// with one's complement representation.

注意:对于那些不知道"枚举范围"的人(虽然是一个非标准术语),请转到此问题。

no。

C 2a/2b反射建议(S)我所看的是,如果缺乏直接性状,则看起来足够强大,可以计算出来。我不知道它们在2020年被标准化的可能性,也不知道最新提案的文本保证100%。