std:: max_align_t
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic types | |||||||||||
| Fixed width integer types (C++11) | |||||||||||
| Fixed width floating-point types (C++23) | |||||||||||
| Numeric limits | |||||||||||
| C numeric limits interface | |||||||||||
| Runtime type information | |||||||||||
|
|||||||||||
|
定义于头文件
<cstddef>
|
||
|
typedef
/* 由实现定义 */
max_align_t
;
|
(C++11 起) | |
std::max_align_t
是一种
标准布局
平凡类型
(C++26 前)
可平凡复制类型
(C++26 起)
,其
对齐要求
至少与所有标量类型的对齐要求同样严格(即不小于任何标量类型的对齐要求)。
std:: is_trivially_default_constructible_v < std :: max_align_t > 的值为 true 。
目录 |
注释
由分配函数(如
std::malloc
)返回的指针已进行适当对齐以适用于任何对象,这意味着其对齐程度至少与
std::max_align_t
同样严格。
示例
#include <cstddef> #include <iostream> int main() { std::cout << alignof(std::max_align_t) << '\n'; }
可能的输出:
16
参考文献
- C++23 标准 (ISO/IEC 14882:2024):
-
- 17.2.4 大小、对齐和偏移 [support.types.layout] (第 504-505 页)
- C++20 标准 (ISO/IEC 14882:2020):
-
- 17.2.4 大小、对齐和偏移 [support.types.layout] (第 507-508 页)
- C++17 标准 (ISO/IEC 14882:2017):
-
- 21.2.4 大小、对齐和偏移 [support.types.layout] (第 479 页)