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
Défini dans l'en-tête <type_traits>
template < class T >
struct is_union ;
(depuis C++11)

std::is_union est un UnaryTypeTrait .

Vérifie si T est un type union . Fournit la constante membre value , qui est égale à true si T est un type union. Sinon, value est égale à false .

Si le programme ajoute des spécialisations pour std::is_union ou std::is_union_v , le comportement est indéfini.

Table des matières

Paramètres du modèle

T - un type à vérifier

Modèle de variable d'assistance

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

Hérité de std:: integral_constant

Constantes membres

value
[static]
true si T est un type union, false sinon
(constante membre publique statique)

Fonctions membres

operator bool
convertit l'objet en bool , retourne value
(fonction membre publique)
operator()
(C++14)
retourne value
(fonction membre publique)

Types membres

Type Définition
value_type bool
type std:: integral_constant < bool , value >

Exemple

#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() {}

Voir aussi

(C++11)
vérifie si un type est un type classe non-union
(modèle de classe)