Defined in header <type_traits> | ||||
---|---|---|---|---|
| (since C++11) |
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. If T
is a reference type, returns the alignment requirements of the type referred to.
If alignof(T)
is not a valid expression, the behavior is undefined.
Helper variable template
| (since C++17) |
Inherited from std::integral_constant
Member constants
value [static] | alignof(T) (public static member constant) |
Member functions
operator std::size_t | converts the object to std::size_t , returns value (public member function) |
operator() (C++14) | returns value (public member function) |
Member types
Type | Definition |
---|---|
value_type | std::size_t |
type | std::integral_constant<std::size_t, value> |
Possible implementation
|
Notes
This type trait predates the alignof keyword, which can be used to obtain the same value with less verbosity.
Example
1 2 3 4 5 6 7 8 9 10 11 | #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:
1 2 3 | 1 4 8 |
See also
alignof operator | queries alignment requirements of a type (since C++11) |
(C++11) | defines the type suitable for use as uninitialized storage for types of given size (class template) |
(C++11) | defines the type suitable for use as uninitialized storage for all given types (class template) |
(C++11) | POD type with alignment requirement as great as any other scalar type (typedef) |
std::experimental::alignment_of_v
(library fundamentals TS) | variable template alias of std::alignment_of::value (variable template) |
Please login to continue.