std::underlying_type
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <type_traits>
|
||
template< class T > struct underlying_type; |
(dal C++11) | |
Definisce un membro
type
typedef del tipo che è il tipo di base per l'enumerazione 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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Membri tipi
Nome
Original: Name The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
type
|
il tipo di base per
T Original: the underlying type for T The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifica] Note
Ogni tipo di enumerazione ha un tipo sottostante, che può essere
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.
You can help to correct and verify the translation. Click here for instructions.
1. Specificato esplicitamente (sia ambito e le enumerazioni senza ambito)
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.
You can help to correct and verify the translation. Click here for instructions.
2. Omissis, nel qual caso è int per le enumerazioni ambito o una implementazione definito di tipo integrale in grado di rappresentare tutti i valori della enum (per le enumerazioni senza ambito)
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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Esempio
#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'; }
Output:
underlying type for 'e1' is unsigned underlying type for 'e2' is int