is_empty Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

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

Tests if type is an empty class.

template <class Ty>  
struct is_empty;  

Parameters

Ty
The type to query.

An instance of the type predicate holds true if the type Ty is an empty class, otherwise it holds false.

// std_tr1__type_traits__is_empty.cpp   
// compile with: /EHsc   
#include <type_traits>   
#include <iostream>   
  
struct empty   
    {   
    };   
  
struct trivial   
    {   
    int val;   
    };   
  
int main()   
    {   
    std::cout << "is_empty<trivial> == " << std::boolalpha   
        << std::is_empty<trivial>::value << std::endl;   
    std::cout << "is_empty<empty> == " << std::boolalpha   
        << std::is_empty<empty>::value << std::endl;   
    std::cout << "is_empty<int> == " << std::boolalpha   
        << std::is_empty<int>::value << std::endl;   
  
    return (0);   
    }  
  

is_empty<trivial> == false  
is_empty<empty> == true  
is_empty<int> == false  

Header: <type_traits>

Namespace: std

<type_traits>

Show: