std::max_align_t
来自 cppreference.cn
定义于头文件 <cstddef> |
||
typedef /* 实现定义 */ 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)