is_standard_layout template in C++
Last Updated :
19 Nov, 2018
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.
#include <iostream>
#include <type_traits>
using namespace std;
class gfg {
int variab;
};
struct sam {
int variab;
private :
int variab_priv;
};
union raj {
};
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;
}
|
Output:
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
#include <iostream>
#include <type_traits>
using namespace std;
class gfg {
int variab;
};
class sam {
int variab;
private :
int variab_priv;
};
class raj {
};
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;
}
|
Output:
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...