std:: is_object
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definiert im Header
<type_traits>
|
||
|
template
<
class
T
>
struct is_object ; |
(seit C++11) | |
std::is_object
ist ein
UnaryTypeTrait
.
Falls
T
ein
Objekttyp
ist (also ein beliebiger möglicherweise cv-qualifizierter Typ außer Funktion, Referenz oder
void
-Typen), stellt die Konstante
value
den Wert
true
bereit. Für alle anderen Typen ist
value
false
.
Wenn das Programm Spezialisierungen für
std::is_object
oder
std::is_object_v
hinzufügt, ist das Verhalten undefiniert.
Inhaltsverzeichnis |
Template-Parameter
| T | - | ein zu prüfender Typ |
Hilfsvariablen-Template
|
template
<
class
T
>
constexpr bool is_object_v = is_object < T > :: value ; |
(seit C++17) | |
Geerbt von std:: integral_constant
Member-Konstanten
|
value
[static]
|
true
wenn
T
ein Objekttyp ist,
false
andernfalls
(öffentliche statische Member-Konstante) |
Member-Funktionen
|
operator bool
|
konvertiert das Objekt zu
bool
, gibt
value
zurück
(öffentliche Member-Funktion) |
|
operator()
(C++14)
|
gibt
value
zurück
(öffentliche Member-Funktion) |
Member-Typen
| Typ | Definition |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
Mögliche Implementierung
template<class T> struct is_object : std::integral_constant<bool, std::is_scalar<T>::value || std::is_array<T>::value || std::is_union<T>::value || std::is_class<T>::value> {}; |
`-Tags liegt und C++-spezifische Begriffe enthält, wurde gemäß den Anweisungen keine Übersetzung durchgeführt. Der Code bleibt vollständig unverändert im Originalzustand erhalten.
Beispiel
#include <iomanip> #include <iostream> #include <type_traits> #define IS_OBJECT(...) \ std::cout << std::boolalpha << std::left << std::setw(9) << #__VA_ARGS__ \ << (std::is_object_v<__VA_ARGS__> ? " is object\n" \ : " is not an object\n") int main() { class cls {}; IS_OBJECT(void); IS_OBJECT(int); IS_OBJECT(int&); IS_OBJECT(int*); IS_OBJECT(int*&); IS_OBJECT(cls); IS_OBJECT(cls&); IS_OBJECT(cls*); IS_OBJECT(int()); IS_OBJECT(int(*)()); IS_OBJECT(int(&)()); }
Ausgabe:
void is not an object int is object int& is not an object int* is object int*& is not an object cls is object cls& is not an object cls* is object int() is not an object int(*)() is object int(&)() is not an object
Siehe auch
|
(C++11)
|
prüft, ob ein Typ ein Skalartyp ist
(Klassentemplate) |
|
(C++11)
|
prüft, ob ein Typ ein Arraytyp ist
(Klassentemplate) |
|
(C++11)
|
prüft, ob ein Typ ein Union-Typ ist
(Klassentemplate) |
|
(C++11)
|
prüft, ob ein Typ ein Klassen-Typ (keine Union) ist
(Klassentemplate) |