is_union Class

 

The latest version of this topic can be found at is_union Class.

Tests if type is a union.

Syntax

template <class Ty>  
struct is_union;  

Parameters

Ty
The type to query.

Remarks

An instance of the type predicate holds true if the type Ty is a union type or a cv-qualified form of a union type, otherwise it holds false.

Example

// std_tr1__type_traits__is_union.cpp   
// compile with: /EHsc   
#include <type_traits>   
#include <iostream>   
  
struct trivial   
    {   
    int val;   
    };   
  
union ints   
    {   
    int in;   
    long lo;   
    };   
  
int main()   
    {   
    std::cout << "is_union<trivial> == " << std::boolalpha   
        << std::is_union<trivial>::value << std::endl;   
    std::cout << "is_union<int> == " << std::boolalpha   
        << std::is_union<int>::value << std::endl;   
    std::cout << "is_union<ints> == " << std::boolalpha   
        << std::is_union<ints>::value << std::endl;   
  
    return (0);   
    }  
  
is_union<trivial> == false  
is_union<int> == false  
is_union<ints> == true  

Requirements

Header: <type_traits>

Namespace: std

See Also

<type_traits>
is_class Class