std::is_convertible
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< class From, class To > struct is_convertible; |
(ya que C + +11) | |
Si un valor p imaginario de tipo
From puede utilizar en la instrucción de retorno de una función que devuelve To, es decir, si se puede convertir en To utilizando implicit conversion, proporciona el miembro constante value igual a true. De lo contrario value es false .Original:
If an imaginary rvalue of type
From can used in the return statement of a function returning To, that is, if it can be converted to To using implicit conversion, provides the member constant value equal to true. Otherwise value 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 |
Inherited from std::integral_constant
Member constants
| value [estático] |
true si From is convertible to To , false lo contrario Original: true if From is convertible to To , false otherwise The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (público miembro constante estática) |
Member functions
| operator bool |
convierte el objeto a bool, devuelve value Original: converts the object to bool, returns value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (miembro público función) |
Member types
| Tipo
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
[editar] Notas
Da resultados bien definidos para los tipos de referencia, los tipos nulos, tipos de matriz y tipos de funciones .
Original:
Gives well-defined results for reference types, void types, array types, and function types.
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.
[editar] Ejemplo
#include <iostream> #include <type_traits> int main() { class A {}; class B: public A {}; class C {}; bool b2a = std::is_convertible<B*, A*>::value; bool a2b = std::is_convertible<A*, B*>::value; bool b2c = std::is_convertible<B*, C*>::value; std::cout << std::boolalpha; std::cout << b2a << '\n'; std::cout << a2b << '\n'; std::cout << b2c << '\n'; }
Output:
true false false