std::is_convertible
Da 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; |
(a partir do C++ 11) | |
Se um tipo de rvalue imaginário
From pode usado na instrução de retorno de uma função To retorno, isto é, se ele pode ser convertido para To usando implicit conversion, fornece o membro constante igual a value true. Caso contrário value é 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.
Índice |
Inherited from std::integral_constant
Member constants
| value [estática] |
true se From is convertible to To , false contrário 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. (membro estático público constante) |
Member functions
| operator bool |
converte o objeto em bool, retorna 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. (função pública membro) |
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
Dá bem definidas resultados para tipos de referência, tipos de vazios, tipos de matriz, e tipos de função.
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] Exemplo
#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