is_empty template in C++
The std::is_empty template of C++ STL is used to check whether the given type is empty or not. This method returns a boolean value showing whether the given type is empty or not.
Syntax:
template < class T > struct is_empty;
Parameters: This template contains single parameter T (Trait class) that identifies whether T is a empty type.
Return Value: This template returns a boolean value as shown below:
- True: if the type is a empty.
- False: if the type is not empty.
Below programs illustrate the std::is_empty template in C++ STL:
Program 1: Using Structs
// C++ program to illustrate // std::is_empty template #include <iostream> #include <type_traits> using namespace std; // empty struct struct GFG1 { }; // struct with local variable struct GFG2 { int variab; }; // Struct with global variable struct GFG3 { static int variab; }; // Struct with virtual destructor struct GFG4 { virtual ~GFG4(); }; // Driver code int main() { cout << boolalpha; cout << "Is GFG1 empty: " << is_empty<GFG1>::value << '\n'; cout << "Is GFG2 empty: " << is_empty<GFG2>::value << '\n'; cout << "Is GFG3 empty: " << is_empty<GFG3>::value << '\n'; cout << "Is GFG4 empty: " << is_empty<GFG4>::value << '\n'; return 0; } |
Is GFG1 empty: true Is GFG2 empty: false Is GFG3 empty: true Is GFG4 empty: false
Program 2: Using classes
// C++ program to illustrate // std::is_empty template #include <iostream> #include <type_traits> using namespace std; // empty class class GFG1 { }; // class with local variable class GFG2 { int variab; }; // class with global variable class GFG3 { static int variab; }; // class with virtual destructor class GFG4 { virtual ~GFG4(); }; int main() { cout << boolalpha; cout << "Is GFG1 empty: " << is_empty<GFG1>::value << '\n'; cout << "Is GFG2 empty: " << is_empty<GFG2>::value << '\n'; cout << "Is GFG3 empty: " << is_empty<GFG3>::value << '\n'; cout << "Is GFG4 empty: " << is_empty<GFG4>::value << '\n'; return 0; } |
Is GFG1 empty: true Is GFG2 empty: false Is GFG3 empty: true Is GFG4 empty: false
Recommended Posts:
- is_const Template in C++
- is_scalar template in C++
- std::is_compound Template in C++
- is_lvalue_reference Template in C++
- is_reference Template in C++
- is_abstract template in C++
- is_polymorphic template in C++
- is_final template in C++14
- is_unsigned template in C++
- is_signed template in C++
- is_volatile template in C++
- is_standard_layout template in C++
- is_void template in C++
- std is_union() template in C++
- is_fundamental Template in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



