std::is_convertible
Aus 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. |
<metanoindex/>
<tbody> </tbody>| definiert in Header <type_traits>
|
||
template< class From, class To > struct is_convertible; |
(seit C++11) | |
Wenn eine imaginäre rvalue vom Typ
From im Rücklauf Anweisung einer Funktion, die verwendet werden können To, das heißt, wenn sie Verwendung To implicit conversion umgewandelt werden kann, stellt die Elementkonstante value gleich true. Ansonsten value ist 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.
Inherited from std::integral_constant
Member constants
value [statisch] |
true wenn From is convertible to To , false anders 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. (public static Mitglied konstanten) |
Member functions
operator bool |
wandelt das Objekt bool, gibt 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. (öffentliche Elementfunktion) |
Member types
Type
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>
|
Notes
Gibt wohldefinierte Ergebnisse für Referenztypen, void-Typen Array-Typen und Funktion Typen .
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.
Beispiel
#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