std::conditional
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<bool B, class T, class F > struct conditional; | (dal C++11) | |
Fornisce
type
typedef membro, che è definito come T
se B
true è in fase di compilazione, o come se F
B
è false.Original:
Provides member typedef
type
, which is defined as T
if B
is true at compile time, or as F
if B
is false.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.
Indice |
[modifica]Membri tipi
Membro tipo Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | Definition |
type | T if B ==true, F if B ==false |
[modifica]Possibile implementazione
template<bool B, class T, class F>struct conditional {typedef T type;}; template<class T, class F>struct conditional<false, T, F>{typedef F type;}; |
[modifica]Esempio
#include <iostream>#include <type_traits>#include <typeinfo> int main(){typedef std::conditional<true, int, double>::type Type1;typedef std::conditional<false, int, double>::type Type2;typedef std::conditional<sizeof(int)>= sizeof(double), int, double>::type Type3; std::cout<<typeid(Type1).name()<<'\n';std::cout<<typeid(Type2).name()<<'\n';std::cout<<typeid(Type3).name()<<'\n';}
Output:
i d d
[modifica]Vedi anche
(C++11) | nasconde un sovraccarico di funzione o modello di specializzazione basato su in fase di compilazione booleano Original: hides a function overload or template specialization based on compile-time boolean The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe template) |