std::alignment_of
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <type_traits>
|
||
| template< class T > struct alignment_of; |
(C++11 起) | |
提供部件恒定
value类型T的对齐要求,等于,仿佛由alignof表达式获得。 T如果是一个数组类型,则返回的元素类型的对齐要求.Original:
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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
Inherited from std::integral_constant
Member constants
| value [静态的] </ SPAN></div></div>
|
alignof(typename std::remove_all_extents<T>::type) (公共静态成员常量) |
Member functions
| operator std::size_t |
转换的对象std::size_t,返回 value Original: converts the object to std::size_t, returns value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) |
Member types
| 类型
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
std::size_t
|
type
|
std::integral_constant<std::size_t, value> |
</div>
[编辑] 可能的实现
template< class T > struct alignment_of : std::integral_constant< std::size_t, alignof(typename std::remove_all_extents<T>::type) > {}; |
[编辑] 为例
#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 4 8
[编辑] 另请参阅
| alignof operator | queries alignment requirements of a type (C++11 起) |
| (C++11) |
定义的类型适合用作未初始化的存储类型的给定尺寸 Original: defines the type suitable for use as uninitialized storage for types of given size The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |
| (C++11) |
适合所有类型的使用未初始化的存储定义的类型 Original: defines the type suitable for use as uninitialized storage for all given types The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (类模板) |
| (C++11) |
POD类型的对齐要求大,任何其他标量类型 Original: POD type with alignment requirement as great as any other scalar type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (的typedef) |