is_standard_layout template in C++
The std::is_standard_layout template of C++ STL is used to check whether the type is a standard layout or not. It returns a boolean value showing the same.
Syntax:
template < class T > struct is_standard_layout;
Parameters: This template contains single parameter T (Trait class) to check whether T is a standard layout type or not.
Return Value: This template returns a boolean value as shown below:
- True: if the type is a standard layout type.
- False: if the type is a non-standard layout type.
Below programs illustrate the std::is_standard_layout template in C++ STL:
Program 1: With Struct, Class and Union combined.
// C++ program to illustrate // std::is_standard_layout template #include <iostream> #include <type_traits> using namespace std; // Class with local variable class gfg { int variab; }; // Structure with local variable struct sam { int variab; private: int variab_priv; }; // Empty union union raj { }; // Driver code int main() { cout << boolalpha; cout << "Is gfg class a standard layout: " << is_standard_layout<gfg>::value << '\n'; cout << "Is structure sam a standard layout: " << is_standard_layout<sam>::value << '\n'; cout << "Is union raj a standard layout: " << is_standard_layout<raj>::value << '\n'; cout << "Is datatype char a standard layout: " << is_standard_layout<char>::value << '\n'; cout << "Is integer array 'int a[10]' a standard layout: " << is_standard_layout<int[10]>::value << '\n'; return 0; } |
Is gfg class a standard layout: true Is structure sam a standard layout: false Is union raj a standard layout: true Is datatype char a standard layout: true Is integer array 'int a[10]' a standard layout: true
Program 2: With Class
// C++ program to illustrate // std::is_standard_layout template #include <iostream> #include <type_traits> using namespace std; // Class with local variable class gfg { int variab; }; // class with local variable class sam { int variab; private: int variab_priv; }; // Empty class class raj { }; // Driver code int main() { cout << boolalpha; cout << "Is gfg class a standard layout: " << is_standard_layout<gfg>::value << '\n'; cout << "Is structure sam a standard layout: " << is_standard_layout<sam>::value << '\n'; cout << "Is union raj a standard layout: " << is_standard_layout<raj>::value << '\n'; cout << "Is pointer 'int(gfg::*)' a standard layout: " << is_standard_layout<int(gfg::*)>::value << '\n'; cout << "Is pointer 'int *' a standard layout: " << is_standard_layout<int*>::value << '\n'; cout << "Is pointer 'nullptr_t' a standard layout: " << is_standard_layout<nullptr_t>::value << '\n'; return 0; } |
Is gfg class a standard layout: true Is structure sam a standard layout: true Is union raj a standard layout: true Is pointer 'int(gfg::*)' a standard layout: true Is pointer 'int *' a standard layout: true Is pointer 'nullptr_t' a standard layout: true
Recommended Posts:
- is_const Template in C++
- std::is_compound Template in C++
- is_scalar template in C++
- is_final template in C++14
- is_volatile template in C++
- is_void template in C++
- is_fundamental Template in C++
- is_pointer Template in C++
- is_arithmetic Template in C++
- std is_union() template in C++
- is_class template in C++
- std::is_enum Template in C++
- std::is_integral template in C++
- std is_floating_point Template in C++
- std is_object 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.



