3
列挙型の値の範囲を知る方法はありますか?私はtype_traits
のようなテンプレートをstd::numeric_limits
のように期待していましたが、誰も見つけられませんでした。例えば固定されていない列挙子の範囲を知ることは可能ですか?
:
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.
注:this questionに行き、「列挙型の範囲」(ただし非標準語)が何であるかを知らない人のために。彼らは直接形質を欠く場合
残念ながら、有効な範囲を決定する複雑な一連のルールがありますが、結果にアクセスするための既成の方法はありません。 (また、ルールは[間違っていると思われます](https://github.com/cplusplus/draft/pull/1349) –
「範囲」とはどういう意味ですか? –
@NeilButterworth http://en.cppreference.com/w/cpp/language/enumと 'static_cast'を検索してください。 –