| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <type_traits> | ||
template<class T> struct alignment_of; | (since C++11) | |
Provides the member constantvalue equal to thealignment requirement of the typeT, as if obtained by analignof expression. IfT is an array type, returns the alignment requirements of the element type. IfT is a reference type, returns the alignment requirements of the type referred to.
Ifalignof(T) is not a valid expression, the behavior is undefined.
If the program adds specializations forstd::alignment_of orstd::alignment_of_v(since C++17), the behavior is undefined.
Contents |
template<class T> constexprstd::size_t alignment_of_v= alignment_of<T>::value; | (since C++17) | |
value [static] | alignof(T) (public static member constant) |
operator std::size_t | converts the object tostd::size_t, returnsvalue (public member function) |
operator() (C++14) | returnsvalue (public member function) |
| Type | Definition |
value_type | std::size_t |
type | std::integral_constant<std::size_t, value> |
template<class T>struct alignment_of:std::integral_constant<std::size_t, alignof(T)>{}; |
This type trait predates thealignof keyword, which can be used to obtain the same value with less verbosity.
#include <cstdint>#include <iostream>#include <type_traits> struct A{};struct B{std::int8_t p;std::int16_t q;}; int main(){std::cout<< std::alignment_of<A>::value<<' ';std::cout<< std::alignment_of<B>::value<<' ';std::cout<< std::alignment_of<int>()<<' ';// alt syntaxstd::cout<< std::alignment_of_v<double><<'\n';// c++17 alt syntax}
Possible output:
1 2 4 8
alignof(C++11) | queries alignment requirements of a type (operator)[edit] |
alignas(C++11) | specifies that the storage for the variable should be aligned by specific amount (specifier)[edit] |
(since C++11)(deprecated in C++23) | defines the type suitable for use as uninitialized storage for types of given size (class template)[edit] |
(since C++11)(deprecated in C++23) | defines the type suitable for use as uninitialized storage for all given types (class template)[edit] |
(C++11) | trivial type with alignment requirement as great as any other scalar type (typedef)[edit] |