std::max_align_t
来自 zh.cppreference.net
| 定义于头文件 <cstddef>
|
||
typedef /* implementation-defined */ 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 页)