template< class T >
struct alignment_of;
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.
If the program adds specializations for std::alignment_of
or std::alignment_of_v
(since C++17), the behavior is undefined.
This type trait predates the alignof keyword, which can be used to obtain the same value with less verbosity.
[edit] Example#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 syntax std::cout << std::alignment_of_v<double> << '\n'; // c++17 alt syntax }
Possible output:
[edit] See alsoalignof
(C++11) queries alignment requirements of a type
alignas
(C++11) specifies that the storage for the variable should be aligned by specific amount
(since C++11)(deprecated in C++23)
defines the type suitable for use as uninitialized storage for types of given size(since C++11)(deprecated in C++23)
defines the type suitable for use as uninitialized storage for all given typesRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4