std::underlying_type — cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Déclaré dans l'en-tête <type_traits> |
||
|
|
(depuis C++11) | |
Définit un type membre de typedef type qui est le type sous-jacent de l'énumération T .
Original:
Defines a member typedef type of type that is the underlying type for the enumeration T.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types de membres
Nom Original: Name The text has been machine-translated via Google Translate. |
Definition |
type
|
le type sous-jacent de Original: the underlying type for The text has been machine-translated via Google Translate. |
Notes
Chaque type d'énumération est un type de sous-jacent, qui peut être
Original:
Each enumeration type has an underlying type, which can be
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1. Spécifiée explicitement (à la fois portée et les énumérations sans portée)
Original:
1. Specified explicitly (both scoped and unscoped enumerations)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2. Omis, auquel cas il est int pour les énumérations de portée ou d'un type défini par la mise en œuvre intégrale capable de représenter toutes les valeurs de l'énumération (pour les énumérations sans portée)
Original:
2. Omitted, in which case it is int for scoped enumerations or an implementation-defined integral type capable of representing all values of the enum (for unscoped enumerations)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exemple
#include <iostream> #include <type_traits> enum e1 {}; enum class e2: int {}; int main() { bool e1_type = std::is_same< unsigned ,typename std::underlying_type<e1>::type >::value; bool e2_type = std::is_same< int ,typename std::underlying_type<e2>::type >::value; std::cout << "underlying type for 'e1' is " << (e1_type?"unsigned":"non-unsigned") << '\n' << "underlying type for 'e2' is " << (e2_type?"int":"non-int") << '\n'; }
Résultat :
underlying type for 'e1' is unsigned underlying type for 'e2' is int