std::max_align_t
来自 cppreference.cn
定义于头文件 <cstddef> |
||
typedef /* implementation-defined */ max_align_t; |
(C++11 起) | |
std::max_align_t
是一个 标准布局 平凡类型 (TrivialType)(C++26 前)可平凡复制类型 (TriviallyCopyable)(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] (p: 504-505)
- C++20 标准 (ISO/IEC 14882:2020)
- 17.2.4 大小、对齐和偏移 [support.types.layout] (p: 507-508)
- C++17 标准 (ISO/IEC 14882:2017)
- 21.2.4 大小、对齐和偏移 [support.types.layout] (p: 479)