std::conditional
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <type_traits>
|
||
| template< bool B, class T, class F > struct conditional; |
(ya que C + +11) | |
Proporciona
type miembro typedef, que se define como T si B es true en tiempo de compilación, o como si F B es 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.
Contenido |
[editar] Tipos de miembros
| Miembro de 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
|
[editar] Posible implementación
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; }; |
[editar] Ejemplo
#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
[editar] Ver también
| (C++11) |
esconde una sobrecarga de la función o especialización plantilla basada en booleana en tiempo de compilación 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. (clase de plantilla) |