From Cppreference
|
|
|
|
|
template< class T > struct alignment_of;
|
|
(C++11 feature)
|
|
|
Provides the member constant value equal to the alignment requirement of the type T, as if obtained by an alignof expression. If T is an array type, returns the alignment requirements of the element type.
Member constants
|
value
|
alignof(typename std::remove_all_extents<T>::type) (public static member constant)
|
Member functions
|
operator std::size_t
|
converts the object to std::size_t, returns value (public member function)
|
Member types
|
Type
|
Definition
|
|
value_type
|
std::size_t
|
|
type
|
std::integral_constant<std::size_t, value>
|
[edit] Equivalent definition
template< class T >
struct alignment_of : std::integral_constant<
std::size_t,
alignof(typename std::remove_all_extents<T>::type)
> {};
|
[edit] Example
#include <iostream>
#include <type_traits>
class A {};
int main()
{
std::cout << std::alignment_of<A>::value << '\n';
std::cout << std::alignment_of<int>::value << '\n';
std::cout << std::alignment_of<double>::value << '\n';
}
Output:
[edit] See also
|
|
(keyword)
|
|
|
defines the type suitable for use as uninitialized storage for types of given size (class template)
|
|
|
defines the type suitable for use as uninitialized storage for all given types (class template)
|
|
|
POD type with alignment requirement as great as any other scalar type (typedef)
|