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
Definido en el encabezado <type_traits>
template < class T >
struct is_union ;
(desde C++11)

std::is_union es un UnaryTypeTrait .

Comprueba si T es un tipo unión . Proporciona la constante miembro value , que es igual a true si T es un tipo unión. De lo contrario, value es igual a false .

Si el programa añade especializaciones para std::is_union o std::is_union_v , el comportamiento es indefinido.

Contenidos

Parámetros de plantilla

T - un tipo a verificar

Plantilla de variable auxiliar

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

Heredado de std:: integral_constant

Constantes miembro

value
[static]
true si T es un tipo unión, false en caso contrario
(constante miembro pública estática)

Funciones miembro

operator bool
convierte el objeto a bool , devuelve value
(función miembro pública)
operator()
(C++14)
devuelve value
(función miembro pública)

Tipos miembro

Tipo Definición
value_type bool
type std:: integral_constant < bool , value >

Ejemplo

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

Véase también

(C++11)
verifica si un tipo es un tipo de clase no-union
(plantilla de clase)