std:: is_compound
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definiert im Header
<type_traits>
|
||
|
template
<
class
T
>
struct is_compound ; |
(seit C++11) | |
std::is_compound
ist ein
UnaryTypeTrait
.
Falls
T
ein zusammengesetzter Typ ist (also Array, Funktion, Objektzeiger, Funktionszeiger, Memberobjektzeiger, Memberfunktionszeiger, Referenz, Klasse, Union oder Enumeration, einschließlich aller cv-qualifizierten Varianten), liefert die Memberkonstante
value
den Wert
true
. Für alle anderen Typen ist
value
false
.
Wenn das Programm Spezialisierungen für
std::is_compound
oder
std::is_compound_v
hinzufügt, ist das Verhalten undefiniert.
Inhaltsverzeichnis |
Template-Parameter
| T | - | ein zu prüfender Typ |
Hilfsvariablen-Template
|
template
<
class
T
>
constexpr bool is_compound_v = is_compound < T > :: value ; |
(seit C++17) | |
Geerbt von std:: integral_constant
Member-Konstanten
|
value
[static]
|
true
wenn
T
ein zusammengesetzter Typ 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 > |
Hinweise
Zusammengesetzte Typen sind die Typen, die aus fundamentalen Typen konstruiert werden. Jeder C++-Typ ist entweder fundamental oder zusammengesetzt.
Mögliche Implementierung
template<class T> struct is_compound : std::integral_constant<bool, !std::is_fundamental<T>::value> {}; |
Beispiel
#include <type_traits> #include <iostream> static_assert(not std::is_compound_v<int>); static_assert(std::is_compound_v<int*>); static_assert(std::is_compound_v<int&>); void f(); static_assert(std::is_compound_v<decltype(f)>); static_assert(std::is_compound_v<decltype(&f)>); static_assert(std::is_compound_v<char[100]>); class C {}; static_assert(std::is_compound_v<C>); union U {}; static_assert(std::is_compound_v<U>); enum struct E { e }; static_assert(std::is_compound_v<E>); static_assert(std::is_compound_v<decltype(E::e)>); struct S { int i : 8; int j; void foo(); }; static_assert(not std::is_compound_v<decltype(S::i)>); static_assert(not std::is_compound_v<decltype(S::j)>); static_assert(std::is_compound_v<decltype(&S::j)>); static_assert(std::is_compound_v<decltype(&S::foo)>); int main() { std::cout << "All checks have passed\n"; }
Siehe auch
|
(C++11)
|
prüft, ob ein Typ ein fundamentaler Typ ist
(Klassentemplate) |
|
(C++11)
|
prüft, ob ein Typ ein skalarer Typ ist
(Klassentemplate) |
|
(C++11)
|
prüft, ob ein Typ ein Objekttyp ist
(Klassentemplate) |
|
(C++11)
|
prüft, ob ein Typ ein Array-Typ ist
(Klassentemplate) |