Namespaces
Variants

std:: is_union

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
(C++11)
(C++11)
is_union
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
Definiert im Header <type_traits>
template < class T >
struct is_union ;
(seit C++11)

std::is_union ist ein UnaryTypeTrait .

Prüft, ob T ein Union-Typ ist. Stellt die Member-Konstante value bereit, die gleich true ist, falls T ein Union-Typ ist. Andernfalls ist value gleich false .

Wenn das Programm Spezialisierungen für std::is_union oder std::is_union_v hinzufügt, ist das Verhalten undefiniert.

Inhaltsverzeichnis

Template-Parameter

T - ein zu prüfender Typ

Hilfsvariablen-Template

template < class T >
constexpr bool is_union_v = is_union < T > :: value ;
(seit C++17)

Geerbt von std:: integral_constant

Member-Konstanten

value
[static]
true wenn T ein Union-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 >

Beispiel

#include <type_traits>
struct A {};
static_assert(!std::is_union_v<A>);
typedef union
{
    int a;
    float b;
} B;
static_assert(std::is_union_v<B>);
struct C { B d; };
static_assert(!std::is_union_v<C>);
static_assert(!std::is_union_v<int>);
int main() {}

Siehe auch

(C++11)
prüft, ob ein Typ ein Nicht-Union-Klassentyp ist
(Klassen-Template)