type_traits::alignment_of template in C++
Last Updated :
26 May, 2021
It is used to find the member constant value equal to the alignment requirement of the type T. If T is a reference type than it returns the alignment requirements of the type referred to. If T is an array type than it returns the alignment requirements of the element type.
Header File:
#include<type_traits>
Syntax:
template
<class T>
struct alignment_of;
Parameter: The template std::alignment_of accepts a single parameter T (Trait class).
Below programs illustrate the std::alignment_of template in C++ STL:
Program 1:
CPP14
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
class GFG {
};
int main()
{
cout << alignment_of<GFG>::value << endl;
cout << alignment_of< int >() << endl;
cout << alignment_of< double >() << endl;
return 0;
}
|
Program 2:
CPP14
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
class GFG {
};
int main()
{
cout << alignment_of<GFG>::value << endl;
cout << alignment_of< float >() << endl;
cout << alignment_of< char >() << endl;
return 0;
}
|
Reference: http://www.cplusplus.com/reference/type_traits/alignment_of/
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...